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 cycles messages. #3972

Merged
merged 6 commits into from
Nov 12, 2024
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ Allow setting permissions lists in init arguments just like in upgrade arguments
- Module hash: f45db224b40fac516c877e3108dc809d4b22fa42d05ee8dfa5002536a3a3daed
- Bump agent-js to fix error code

### chore!: improve the messages for the subcommands of `dfx cycles`.

If users run subcommands of `dfx cycles` without the `--ic` flag, show below messages to indicate what to do next.
```
Error explanation:
Cycles ledger with canister ID 'um5iw-rqaaa-aaaaq-qaaba-cai' is not installed.
How to resolve the error:
Run the command with '--ic' flag if you want to manage the cycles on the mainnet.
```

# 0.24.2

### feat: Support canister log allowed viewer list
Expand Down
7 changes: 7 additions & 0 deletions e2e/tests-dfx/cycles-ledger.bash
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ current_time_nanoseconds() {
assert_eq "2.900 TC (trillion cycles)."
}

@test "balance without cycles ledger fails as expected" {
dfx_start

assert_command_fail dfx cycles balance
assert_contains "Cycles ledger with canister ID 'um5iw-rqaaa-aaaaq-qaaba-cai' is not installed."
}

@test "transfer" {
start_and_install_nns

Expand Down
17 changes: 17 additions & 0 deletions src/dfx/src/lib/diagnosis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub fn diagnose(err: &AnyhowError) -> Diagnosis {
} else if *agent_err == AgentError::CertificateNotAuthorized() {
return subnet_not_authorized();
}
if cycles_ledger_not_found(err) {
return diagnose_cycles_ledger_not_found();
}
}

if local_replica_not_running(err) {
Expand Down Expand Up @@ -229,3 +232,17 @@ If you're using a local replica and configuring a wallet was a mistake, you can
recreate the replica with `dfx stop && dfx start --clean` to start over.";
(Some(explanation.to_string()), Some(suggestion.to_string()))
}

fn cycles_ledger_not_found(err: &AnyhowError) -> bool {
err.to_string()
.contains("Canister um5iw-rqaaa-aaaaq-qaaba-cai not found")
}

fn diagnose_cycles_ledger_not_found() -> Diagnosis {
let explanation =
"Cycles ledger with canister ID 'um5iw-rqaaa-aaaaq-qaaba-cai' is not installed.";
let suggestion =
"Run the command with '--ic' flag if you want to manage the cycles on the mainnet.";

(Some(explanation.to_string()), Some(suggestion.to_string()))
}
Loading