Skip to content

Commit

Permalink
Update error message checks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity committed Jan 29, 2025
1 parent d0b904d commit a687ef3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
12 changes: 6 additions & 6 deletions e2e/tests-dfx/call.bash
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function impersonate_sender() {

# test management canister call failure (setting memory allocation to a low value)
assert_command_fail dfx canister update-settings hello_backend --memory-allocation 1 --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Management canister call failed: IC0402: Canister was given 1 B memory allocation but at least"
assert_contains "Canister was given 1 B memory allocation but at least"

# canister status fails because the default identity does not control the canister anymore
assert_command_fail dfx canister status hello_backend
Expand All @@ -334,22 +334,22 @@ function impersonate_sender() {

# test management canister call submission failure
assert_command_fail dfx canister status hello_backend --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Failed to submit management canister call: IC0207: Canister $CANISTER_ID is out of cycles"
assert_contains "Failed to submit management canister call: Canister $CANISTER_ID is out of cycles"

# test update call submission failure
assert_command_fail dfx canister call aaaaa-aa canister_status "(record { canister_id=principal\"$CANISTER_ID\" })" --update --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Failed to submit canister call: IC0207: Canister $CANISTER_ID is out of cycles"
assert_contains "Failed to submit canister call: Canister $CANISTER_ID is out of cycles"

# test async call submission failure
assert_command_fail dfx canister call aaaaa-aa canister_status "(record { canister_id=principal\"$CANISTER_ID\" })" --async --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Failed to submit canister call: IC0207: Canister $CANISTER_ID is out of cycles"
assert_contains "Failed to submit canister call: Canister $CANISTER_ID is out of cycles"

# unfreeze the canister
assert_command dfx canister update-settings hello_backend --freezing-threshold 0 --impersonate "${IDENTITY_PRINCIPAL}"

# test update call failure
assert_command_fail dfx canister call aaaaa-aa delete_canister "(record { canister_id=principal\"$CANISTER_ID\" })" --update --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Canister call failed: IC0510: Canister $CANISTER_ID must be stopped before it is deleted."
assert_contains "Canister call failed: Canister $CANISTER_ID must be stopped before it is deleted."

# test update call
assert_command dfx canister call aaaaa-aa start_canister "(record { canister_id=principal\"$CANISTER_ID\" })" --update --impersonate "${IDENTITY_PRINCIPAL}"
Expand All @@ -361,7 +361,7 @@ function impersonate_sender() {

# test query call failure
assert_command_fail dfx canister call aaaaa-aa fetch_canister_logs "(record { canister_id=principal\"$CANISTER_ID\" })" --query --impersonate "$CANISTER_ID"
assert_contains "Failed to perform query call: IC0406: Caller $CANISTER_ID is not allowed to query ic00 method fetch_canister_logs"
assert_contains "Failed to perform query call: Caller $CANISTER_ID is not allowed to query ic00 method fetch_canister_logs"

# test query call
assert_command dfx canister call aaaaa-aa fetch_canister_logs "(record { canister_id=principal\"$CANISTER_ID\" })" --query --impersonate "${IDENTITY_PRINCIPAL}"
Expand Down
35 changes: 28 additions & 7 deletions src/dfx/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,13 @@ To figure out the id of your wallet, run 'dfx identity get-wallet (--network ic)
arg_value,
)
.await
.map_err(|err| anyhow!("Failed to perform query call: {}", err))?
.map_err(|err| {
anyhow!(
"Failed to perform query call: {} ({})",
err.reject_message,
err.error_code
)
})?
} else {
bail!("Impersonating sender is only supported for a local PocketIC instance.")
}
Expand Down Expand Up @@ -411,7 +417,13 @@ To figure out the id of your wallet, run 'dfx identity get-wallet (--network ic)
arg_value,
)
.await
.map_err(|err| anyhow!("Failed to submit canister call: {}", err))?
.map_err(|err| {
anyhow!(
"Failed to submit canister call: {} ({})",
err.reject_message,
err.error_code
)
})?
.message_id;
CallResponse::Poll(RequestId::new(msg_id.as_slice().try_into().unwrap()))
} else {
Expand Down Expand Up @@ -460,11 +472,20 @@ To figure out the id of your wallet, run 'dfx identity get-wallet (--network ic)
arg_value,
)
.await
.map_err(|err| anyhow!("Failed to submit canister call: {}", err))?;
pocketic
.await_call_no_ticks(msg_id)
.await
.map_err(|err| anyhow!("Canister call failed: {}", err))?
.map_err(|err| {
anyhow!(
"Failed to submit canister call: {} ({})",
err.reject_message,
err.error_code
)
})?;
pocketic.await_call_no_ticks(msg_id).await.map_err(|err| {
anyhow!(
"Canister call failed: {} ({})",
err.reject_message,
err.error_code
)
})?
} else {
bail!("Impersonating sender is only supported for a local PocketIC instance.")
}
Expand Down
25 changes: 19 additions & 6 deletions src/dfx/src/lib/operations/canister/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,20 @@ where
encode_args((arg,)).unwrap(),
)
.await
.map_err(|err| anyhow!("Failed to submit management canister call: {}", err))?;
let data = pocketic
.await_call_no_ticks(msg_id)
.await
.map_err(|err| anyhow!("Management canister call failed: {}", err))?;
.map_err(|err| {
anyhow!(
"Failed to submit management canister call: {} ({})",
err.reject_message,
err.error_code
)
})?;
let data = pocketic.await_call_no_ticks(msg_id).await.map_err(|err| {
anyhow!(
"Management canister call failed: {} ({})",
err.reject_message,
err.error_code
)
})?;

decode_args(&data).context("Could not decode management canister response.")?
} else {
Expand Down Expand Up @@ -146,7 +155,11 @@ where
)
.await
.map_err(|err| {
anyhow!("Failed to perform management canister query call: {}", err)
anyhow!(
"Failed to perform management canister query call: {} ({})",
err.reject_message,
err.error_code
)
})?;
decode_args(&data)
.context("Failed to decode management canister query call response.")?
Expand Down

0 comments on commit a687ef3

Please sign in to comment.