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 error message for 'dfx deploy'. #4018

Merged
merged 8 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ This affects the following commands:
- `dfx canister update-settings`
- `dfx ledger fabricate-cycles`

### 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
18 changes: 18 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,14 @@ fn diagnose_ledger_not_found() -> Diagnosis {

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

fn insufficient_cycles(err: &CreateCanisterError) -> bool {
matches!(err, CreateCanisterError::InsufficientFunds { balance: _ })
vincent-dfinity marked this conversation as resolved.
Show resolved Hide resolved
}

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()))
}
Loading