Skip to content

Commit c5c7f47

Browse files
committed
improve error handling
1 parent 10b6b83 commit c5c7f47

File tree

1 file changed

+15
-6
lines changed
  • crates/anvil-polkadot/src/api_server

1 file changed

+15
-6
lines changed

crates/anvil-polkadot/src/api_server/server.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,11 @@ async fn create_revive_rpc_client(substrate_service: &Service) -> Result<EthRpcC
475475
)));
476476
};
477477

478-
let runtime_version = substrate_service
479-
.client
480-
.runtime_version_at(genesis_hash)
481-
.expect("Runtime version not found for given genesis hash");
478+
let Ok(runtime_version) = substrate_service.client.runtime_version_at(genesis_hash) else {
479+
return Err(Error::InvalidParams(
480+
"Runtime version not found for given genesis hash".to_string(),
481+
));
482+
};
482483
let subxt_runtime_version = SubxtRuntimeVersion {
483484
spec_version: runtime_version.spec_version,
484485
transaction_version: runtime_version.transaction_version,
@@ -487,8 +488,16 @@ async fn create_revive_rpc_client(substrate_service: &Service) -> Result<EthRpcC
487488
let code_bytes = substrate_service
488489
.client
489490
.storage(genesis_hash, &StorageKey(CODE_KEY.to_vec()))
490-
.expect("Runtime code not found for given genesis hash")
491-
.unwrap();
491+
.map_err(|_| {
492+
Error::InvalidParams(
493+
"Failed to access runtime code storage for given genesis hash".to_string(),
494+
)
495+
})?
496+
.ok_or_else(|| {
497+
Error::InvalidParams(
498+
"Runtime code not found in storage for given genesis hash".to_string(),
499+
)
500+
})?;
492501
let opaque_metadata = fetch_latest_metadata_from_code_blob(
493502
&WasmExecutor::<SubstrateHostFunctions>::builder().build(),
494503
Cow::Borrowed(code_bytes.0.as_slice()),

0 commit comments

Comments
 (0)