From bca96728ee5220cd41e4b75844122be4cd576751 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 29 Oct 2024 18:33:39 +0800 Subject: [PATCH 1/3] Improve the error message for 'dfx deploy'. --- e2e/tests-dfx/deploy.bash | 5 +++++ src/dfx/src/commands/deploy.rs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/e2e/tests-dfx/deploy.bash b/e2e/tests-dfx/deploy.bash index 709f912f8e..b93b129292 100644 --- a/e2e/tests-dfx/deploy.bash +++ b/e2e/tests-dfx/deploy.bash @@ -187,6 +187,11 @@ teardown() { assert_contains "Creating a wallet canister" } +@test "deploy without starting returns the correct error message" { + assert_command_fail dfx deploy + assert_contains "Failed to fetch the root key, did you run 'dfx start' to start the local replica?" +} + @test "can deploy gzip wasm" { jq '.canisters.hello_backend.gzip=true' dfx.json | sponge dfx.json dfx_start diff --git a/src/dfx/src/commands/deploy.rs b/src/dfx/src/commands/deploy.rs index 78751a62de..d3ab482693 100644 --- a/src/dfx/src/commands/deploy.rs +++ b/src/dfx/src/commands/deploy.rs @@ -162,7 +162,9 @@ 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))?; - runtime.block_on(fetch_root_key_if_needed(&env))?; + // 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(deploy_canisters( &env, From cf4ef4010cae24f35e5b1a974ba1cad5cff61324 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 29 Oct 2024 21:33:35 +0800 Subject: [PATCH 2/3] 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(()) } From 260c9577fd655bc9699e945ad39c0fba15b0733c Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Tue, 29 Oct 2024 22:32:55 +0800 Subject: [PATCH 3/3] Update CHANGELOG.md. --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a29863ab7..6446d99042 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ Allow setting permissions lists in init arguments just like in upgrade arguments - Module hash: 2c24b5e1584890a7965011d5d1d827aca68c489c9a6308475730420fa53372e8 - https://github.com/dfinity/sdk/pull/3965 +### chore!: improve `dfx deploy` messages. + +If users run `dfx deploy` without running `dfx start`, show below messages to indicate what to do next. +``` +Error: Failed to fetch the root key, did you run 'dfx start' to start the local replica? +An error happened during communication with the replica: error sending request for url (http://127.0.0.1:4943/api/v2/status) +``` + # 0.24.2 ### feat: Support canister log allowed viewer list