From 8948d04f052f36379d28cee7c122e1a96d544ce1 Mon Sep 17 00:00:00 2001 From: juanbono Date: Mon, 15 Jan 2024 16:58:42 -0300 Subject: [PATCH] improve error handling --- .../src/api_server/web3/namespaces/zks.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs b/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs index 875d177ce8c..6e916653056 100644 --- a/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs +++ b/core/lib/zksync_core/src/api_server/web3/namespaces/zks.rs @@ -132,14 +132,16 @@ impl ZksNamespace { // read the address from the native_erc20.json file. // in the future it should be read from .init.env file - let native_erc20_file = - File::open(NATIVE_ERC20_FILE_PATH).map_err(|err| internal_error(METHOD_NAME, err))?; + let native_erc20_file = File::open(NATIVE_ERC20_FILE_PATH) + .map_err(|_err| internal_error(METHOD_NAME, "unable to read native_erc20.json file"))?; let native_erc20_json: serde_json::Value = - serde_json::from_reader(BufReader::new(native_erc20_file)) - .map_err(|err| internal_error(METHOD_NAME, err))?; + serde_json::from_reader(BufReader::new(native_erc20_file)).map_err(|_err| { + internal_error(METHOD_NAME, "unable to read native_erc20.json file") + })?; - let native_erc20_address = native_erc20_json["address"] - .as_str() + let native_erc20_address = native_erc20_json + .get("address") + .and_then(|addr| addr.as_str()) .ok_or_else(|| internal_error(METHOD_NAME, "address not found in json"))?; H160::from_str(native_erc20_address).map_err(|err| internal_error(METHOD_NAME, err))