From cf4ef4010cae24f35e5b1a974ba1cad5cff61324 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 29 Oct 2024 21:33:35 +0800 Subject: [PATCH] Move the error handling to 'fetch_root_key_if_needed'. --- src/dfx/src/commands/deploy.rs | 4 +--- src/dfx/src/lib/root_key.rs | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/dfx/src/commands/deploy.rs b/src/dfx/src/commands/deploy.rs index d3ab482693..78751a62de 100644 --- a/src/dfx/src/commands/deploy.rs +++ b/src/dfx/src/commands/deploy.rs @@ -162,9 +162,7 @@ pub fn exec(env: &dyn Environment, opts: DeployOpts) -> DfxResult { let call_sender = CallSender::from(&opts.wallet, env.get_network_descriptor()) .map_err(|e| anyhow!("Failed to determine call sender: {}", e))?; - // This is where we try to talk to replica first. - runtime.block_on(fetch_root_key_if_needed(&env)) - .map_err(|e| anyhow!("Failed to fetch the root key, did you run 'dfx start' to start the local replica?\n{}", e))?; + runtime.block_on(fetch_root_key_if_needed(&env))?; runtime.block_on(deploy_canisters( &env, diff --git a/src/dfx/src/lib/root_key.rs b/src/dfx/src/lib/root_key.rs index 6fda3a4b5c..7e6877f727 100644 --- a/src/dfx/src/lib/root_key.rs +++ b/src/dfx/src/lib/root_key.rs @@ -1,11 +1,12 @@ use crate::{lib::error::DfxResult, Environment}; - +use anyhow::anyhow; use dfx_core::network::root_key; pub async fn fetch_root_key_if_needed(env: &dyn Environment) -> DfxResult { let agent = env.get_agent(); let network = env.get_network_descriptor(); - root_key::fetch_root_key_when_non_mainnet(agent, network).await?; + root_key::fetch_root_key_when_non_mainnet(agent, network).await + .map_err(|e| anyhow!("Failed to fetch the root key, did you run 'dfx start' to start the local replica?\n{}", e))?; Ok(()) }