From 3386fb7037471604e8de2bb4d734864cef42fda1 Mon Sep 17 00:00:00 2001 From: Adam Spofford Date: Tue, 21 Jun 2022 11:05:13 -0700 Subject: [PATCH 1/4] Provide useful error when `provisional_create_canister_with_cycles` 404s --- .../src/lib/operations/canister/create_canister.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dfx/src/lib/operations/canister/create_canister.rs b/src/dfx/src/lib/operations/canister/create_canister.rs index 57c547d8ab..180d36e2d0 100644 --- a/src/dfx/src/lib/operations/canister/create_canister.rs +++ b/src/dfx/src/lib/operations/canister/create_canister.rs @@ -9,6 +9,7 @@ use crate::lib::waiter::waiter_with_timeout; use anyhow::{anyhow, bail, Context}; use fn_error_context::context; +use ic_agent::agent_error::HttpErrorPayload; use ic_agent::AgentError; use ic_utils::interfaces::ManagementCanister; use slog::info; @@ -85,14 +86,16 @@ pub async fn create_canister( builder = builder.with_controller(controller); } }; - builder + let res = builder .with_optional_compute_allocation(settings.compute_allocation) .with_optional_memory_allocation(settings.memory_allocation) .with_optional_freezing_threshold(settings.freezing_threshold) .call_and_wait(waiter_with_timeout(timeout)) - .await - .context("Canister creation call failed.")? - .0 + .await; + if let Err(AgentError::HttpError(HttpErrorPayload { status: 404, .. })) = &res { + bail!("Cannot ledgerlessly create a canister on this network without a wallet (did you mean `dfx ledger create-canister`?)") + } + res.context("Canister creation call failed.")?.0 } CallSender::Wallet(wallet_id) => { let wallet = Identity::build_wallet_canister(*wallet_id, env).await?; From 0e8025f541b09c139d0bffb9396689daf29e1885 Mon Sep 17 00:00:00 2001 From: Adam Spofford Date: Tue, 21 Jun 2022 11:09:55 -0700 Subject: [PATCH 2/4] Add test --- e2e/tests-dfx/create.bash | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/e2e/tests-dfx/create.bash b/e2e/tests-dfx/create.bash index b6b2fa9204..3756099ea2 100644 --- a/e2e/tests-dfx/create.bash +++ b/e2e/tests-dfx/create.bash @@ -230,3 +230,8 @@ teardown() { assert_command dfx --identity alice canister create --all --controller alice --controller bob } +@test "canister-create on mainnet without wallet does not propagate the 404" { + dfx_start + assert_command_fail dfx deploy --network ic --no-wallet + assert_match 'dfx ledger create-canister' +} From 3bdfb6bba9e3140bbaefe2f0bb1a47f8d8733a22 Mon Sep 17 00:00:00 2001 From: Adam Spofford Date: Tue, 21 Jun 2022 11:51:36 -0700 Subject: [PATCH 3/4] Remove useless step --- e2e/tests-dfx/create.bash | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/tests-dfx/create.bash b/e2e/tests-dfx/create.bash index 3756099ea2..32cd6b2461 100644 --- a/e2e/tests-dfx/create.bash +++ b/e2e/tests-dfx/create.bash @@ -231,7 +231,6 @@ teardown() { } @test "canister-create on mainnet without wallet does not propagate the 404" { - dfx_start assert_command_fail dfx deploy --network ic --no-wallet assert_match 'dfx ledger create-canister' } From 758c6c991038cca5ec872227eca7847a1eb2de91 Mon Sep 17 00:00:00 2001 From: Adam Spofford Date: Tue, 21 Jun 2022 11:51:43 -0700 Subject: [PATCH 4/4] Longer message --- src/dfx/src/lib/operations/canister/create_canister.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/dfx/src/lib/operations/canister/create_canister.rs b/src/dfx/src/lib/operations/canister/create_canister.rs index 180d36e2d0..67b6a8cbab 100644 --- a/src/dfx/src/lib/operations/canister/create_canister.rs +++ b/src/dfx/src/lib/operations/canister/create_canister.rs @@ -93,7 +93,9 @@ pub async fn create_canister( .call_and_wait(waiter_with_timeout(timeout)) .await; if let Err(AgentError::HttpError(HttpErrorPayload { status: 404, .. })) = &res { - bail!("Cannot ledgerlessly create a canister on this network without a wallet (did you mean `dfx ledger create-canister`?)") + bail!("In order to create a canister on this network, you must use a wallet in order to allocate cycles to the new canister. \ + To do this, remove the --no-wallet argument and try again. It is also possible to create a canister on this network \ + using `dfx ledger create-canister`, but doing so will not associate the created canister with any of the canisters in your project.") } res.context("Canister creation call failed.")?.0 }