Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve dfx deploy message. #3967

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions e2e/tests-dfx/deploy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
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))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at DiagnosedError. It may provide even more readable output, by first displaying the error, then displaying the explanation, and finally displaying a suggested action. You'd add it here with something like .context(DiagnosedError::new(...)).

Ok(())
}

Expand Down
Loading