diff --git a/src/dfx/src/lib/diagnosis.rs b/src/dfx/src/lib/diagnosis.rs index ecf12e9c7b..9673f87ac0 100644 --- a/src/dfx/src/lib/diagnosis.rs +++ b/src/dfx/src/lib/diagnosis.rs @@ -35,29 +35,27 @@ impl DiagnosedError { /// Attempts to give helpful suggestions on how to resolve errors. pub fn diagnose(_env: &dyn Environment, err: &AnyhowError) -> Diagnosis { if let Some(diagnosed_error) = err.downcast_ref::() { - ( + return ( diagnosed_error.error_explanation.clone(), diagnosed_error.action_suggestion.clone(), - ) - } else if let Some(agent_err) = err.downcast_ref::() { - match agent_err { - AgentError::HttpError(payload) => match payload.status { - 403 => diagnose_http_403(), - 400 => match std::str::from_utf8(payload.content.as_slice()) { - Ok("Wrong sender") => { - // differing behavior between replica and ic-ref: - // replica gives HTTP403, ic-ref gives HTTP400 with message "Wrong sender" - diagnose_http_403() - } - _ => NULL_DIAGNOSIS, - }, - _ => NULL_DIAGNOSIS, - }, - _ => NULL_DIAGNOSIS, + ); + } + + if let Some(agent_err) = err.downcast_ref::() { + if not_a_controller(agent_err) { + return diagnose_http_403(); } - } else { - NULL_DIAGNOSIS } + + NULL_DIAGNOSIS +} + +fn not_a_controller(err: &AgentError) -> bool { + // differing behavior between replica and ic-ref: + // replica gives HTTP403, ic-ref gives HTTP400 with message "Wrong sender" + matches!(err, AgentError::HttpError(payload) if payload.status == 403) + || matches!(err, AgentError::HttpError(payload) if payload.status == 400 && + matches!(std::str::from_utf8(payload.content.as_slice()), Ok("Wrong sender"))) } fn diagnose_http_403() -> Diagnosis {