Skip to content

Commit

Permalink
Improve error message for 'dfx deploy'.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-dfinity committed Nov 26, 2024
1 parent 1acb8fb commit 8a07dfd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ Added a flag `--replica` to `dfx start`. This flag currently has no effect.
Once PocketIC becomes the default for `dfx start` this flag will start the replica instead.
You can use the `--replica` flag already to write scripts that anticipate that change.

### chore: improve `dfx deploy` messages.

If users run `dfx deploy` without enough cycles, show additional messages to indicate what to do next.
```
Error explanation:
Insufficient cycles balance to create the canister.
How to resolve the error:
Please top up your cycles balance by converting ICP to cycles like below:
'dfx cycles convert --amount=0.123 --ic'.
```

# 0.24.3

### feat: Bitcoin support in PocketIC
Expand Down
21 changes: 21 additions & 0 deletions src/dfx/src/lib/diagnosis.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::lib::cycles_ledger_types::create_canister::CreateCanisterError;
use crate::lib::error_code;
use anyhow::Error as AnyhowError;
use dfx_core::error::root_key::FetchRootKeyError;
Expand Down Expand Up @@ -72,6 +73,12 @@ pub fn diagnose(err: &AnyhowError) -> Diagnosis {
}
}

if let Some(_create_canister_err) = err.downcast_ref::<CreateCanisterError>() {
if insufficient_cycles(_create_canister_err) {
return diagnose_insufficient_cycles();
}
}

NULL_DIAGNOSIS
}

Expand Down Expand Up @@ -262,3 +269,17 @@ fn diagnose_ledger_not_found() -> Diagnosis {

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

fn insufficient_cycles(err: &CreateCanisterError) -> bool {
match err {
CreateCanisterError::InsufficientFunds { balance: _ } => true,
_ => false,
}
}

fn diagnose_insufficient_cycles() -> Diagnosis {
let explanation = "Insufficient cycles balance to create the canister.";
let suggestion = "Please top up your cycles balance by converting ICP to cycles like below:
'dfx cycles convert --amount=0.123 --ic'.";
(Some(explanation.to_string()), Some(suggestion.to_string()))
}

0 comments on commit 8a07dfd

Please sign in to comment.