Skip to content

Commit

Permalink
Move the error handling to 'fetch_root_key_if_needed'.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-dfinity committed Oct 29, 2024
1 parent bca9672 commit cf4ef40
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/dfx/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/dfx/src/lib/root_key.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

Expand Down

0 comments on commit cf4ef40

Please sign in to comment.