diff --git a/CHANGELOG.md b/CHANGELOG.md index 169c256710..2b4112edb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/e2e/tests-dfx/cycles-ledger.bash b/e2e/tests-dfx/cycles-ledger.bash index 1b36725427..481923ec32 100644 --- a/e2e/tests-dfx/cycles-ledger.bash +++ b/e2e/tests-dfx/cycles-ledger.bash @@ -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 diff --git a/src/dfx/src/lib/diagnosis.rs b/src/dfx/src/lib/diagnosis.rs index 1eaa1b6f2c..e59a810da7 100644 --- a/src/dfx/src/lib/diagnosis.rs +++ b/src/dfx/src/lib/diagnosis.rs @@ -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) { @@ -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())) +}