Skip to content

Commit 3f639e1

Browse files
authored
[server] Slightly simpler error handling (#392)
1 parent 7f4825f commit 3f639e1

File tree

1 file changed

+31
-33
lines changed

1 file changed

+31
-33
lines changed

crates/key-server/src/server.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -431,46 +431,44 @@ impl Server {
431431
.dry_run_transaction_block(tx_data)
432432
.await
433433
.map_err(|e| {
434-
if let Error::RpcError(ClientError::Call(ref e)) = e {
435-
match e.code() {
436-
INVALID_PARAMS_CODE => {
437-
// This error is generic and happens when one of the parameters of the Move call in the PTB is invalid.
438-
// One reason is that one of the parameters does not exist, in which case it could be a newly created object that the FN has not yet seen.
439-
// There are other possible reasons, so we return the entire message to the user to allow debugging.
440-
// Note that the message is a message from the JSON RPC API, so it is already formatted and does not contain any sensitive information.
441-
debug!("Invalid parameter: {}", e.message());
442-
return InternalError::InvalidParameter(e.message().to_string());
443-
}
444-
METHOD_NOT_FOUND_CODE => {
445-
// This means that the seal_approve function is not found on the given module.
446-
debug!("Function not found: {:?}", e);
447-
return InternalError::InvalidPTB(
448-
"The seal_approve function was not found on the module".to_string(),
449-
);
450-
}
451-
_ => {}
434+
match e {
435+
Error::RpcError(ClientError::Call(ref e))
436+
if e.code() == INVALID_PARAMS_CODE =>
437+
{
438+
// This error is generic and happens when one of the parameters of the Move call in the PTB is invalid.
439+
// One reason is that one of the parameters does not exist, in which case it could be a newly created object that the FN has not yet seen.
440+
// There are other possible reasons, so we return the entire message to the user to allow debugging.
441+
// Note that the message is a message from the JSON RPC API, so it is already formatted and does not contain any sensitive information.
442+
debug!("Invalid parameter: {}", e.message());
443+
InternalError::InvalidParameter(e.message().to_string())
444+
}
445+
Error::RpcError(ClientError::Call(ref e))
446+
if e.code() == METHOD_NOT_FOUND_CODE =>
447+
{
448+
// This means that the seal_approve function is not found on the given module.
449+
debug!("Function not found: {:?}", e);
450+
InternalError::InvalidPTB(
451+
"The seal_approve function was not found on the module".to_string(),
452+
)
452453
}
454+
_ => InternalError::Failure(format!(
455+
"Dry run execution failed ({e:?}) (req_id: {req_id:?})"
456+
)),
453457
}
454-
InternalError::Failure(format!(
455-
"Dry run execution failed ({e:?}) (req_id: {req_id:?})"
456-
))
457458
})?;
458459

460+
debug!("Dry run response: {:?} (req_id: {:?})", dry_run_res, req_id);
461+
459462
// Record the gas cost. Only do this in permissioned mode to avoid high cardinality metrics in public mode.
460-
if let Some(m) = metrics {
461-
if matches!(
462-
self.options.server_mode,
463-
ServerMode::Permissioned { client_configs: _ }
464-
) {
465-
let package = vptb.pkg_id().to_hex_uncompressed();
466-
m.dry_run_gas_cost_per_package
467-
.with_label_values(&[&package])
468-
.observe(dry_run_res.effects.gas_cost_summary().computation_cost as f64);
469-
}
463+
if let Some(m) = metrics
464+
&& matches!(self.options.server_mode, ServerMode::Permissioned { .. })
465+
{
466+
let package = vptb.pkg_id().to_hex_uncompressed();
467+
m.dry_run_gas_cost_per_package
468+
.with_label_values(&[&package])
469+
.observe(dry_run_res.effects.gas_cost_summary().computation_cost as f64);
470470
}
471471

472-
debug!("Dry run response: {:?} (req_id: {:?})", dry_run_res, req_id);
473-
474472
// Check if the staleness check failed
475473
if self
476474
.options

0 commit comments

Comments
 (0)