Skip to content

Commit

Permalink
chore: improve dfx cycles messages. (#3972)
Browse files Browse the repository at this point in the history
* Diagnose cycles ledger not found error.

* Add tests and update the changelog.

* Fix tests by starting dfx first.

* Fixed review comments by updating the wordings.
  • Loading branch information
vincent-dfinity authored Nov 12, 2024
1 parent 985bd83 commit 6af08b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
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()))
}

0 comments on commit 6af08b9

Please sign in to comment.