From 44a03aa727cc73d04c68d758242c09680952d189 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Wed, 27 Nov 2024 19:55:56 +0800 Subject: [PATCH] Show the correct command according to the network. --- CHANGELOG.md | 2 +- src/dfx/src/lib/diagnosis.rs | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d518063047..3145adec2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,7 +45,7 @@ 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'. +'dfx cycles convert --amount=0.123'. ``` # 0.24.3 diff --git a/src/dfx/src/lib/diagnosis.rs b/src/dfx/src/lib/diagnosis.rs index 2359a92d04..b346341cf7 100644 --- a/src/dfx/src/lib/diagnosis.rs +++ b/src/dfx/src/lib/diagnosis.rs @@ -2,6 +2,7 @@ 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; +use dfx_core::network::provider::get_network_context; use ic_agent::agent::{RejectCode, RejectResponse}; use ic_agent::AgentError; use ic_asset::error::{GatherAssetDescriptorsError, SyncError, UploadContentError}; @@ -275,8 +276,22 @@ fn insufficient_cycles(err: &CreateCanisterError) -> bool { } fn diagnose_insufficient_cycles() -> Diagnosis { + let network = match get_network_context() { + Ok(value) => { + if value == "local" { + "".to_string() + } else { + format!(" --network {}", value) + } + } + Err(_) => "".to_string(), + }; + 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())) + let suggestion = format!( + "Please top up your cycles balance by converting ICP to cycles like below: +'dfx cycles convert --amount=0.123{}'", + network + ); + (Some(explanation.to_string()), Some(suggestion)) }