Configure error message returned by inspect_message

When a call is rejected by inspect_message method, the client receive 403 response code with the body “Requested canister rejected the message”. There seems to be no way to change the returned text to tell the client specifics about the reason for rejection:

  1. Not calling accept_message, trapping with any message, panicking with any message all produce the same result.
  2. Calling something like reject_message produces 500 response code (due to contract violation, this method cannot be called from inspect_message).

So, the question is, do I miss something and there’s some hidden way to return a more specific error message to the client. And if not, is it somewhere on the roadmap?

Panicking / an explicit trap should get you the behavior you are looking for - are you sure that it does not? Just tested locally.

Hmm. I’m pretty sure it doesn’t work for me. I have these code inside my inspect_message:

            ic_cdk::println!("Print before PANIC");
            panic!("PANIC");

And after calling an update method, I can see in the logs of dfx:

[Canister rrkah-fqaaa-aaaaa-aaaaq-cai] Print before PANIC
[Canister rrkah-fqaaa-aaaaa-aaaaq-cai] Panicked at 'PANIC', src/token/src/canister/inspect.rs:74:13

But the response from the canister is:

Error: The replica returned an HTTP Error: Http Error: status 403 Forbidden, content type "", content: Requested canister rejected the message

I would expect the response content to contain the string PANIC somewhere. @AdamS Where do you see the message from the inspect_message?

And yes, trapping produces exactly same result, but without the line Panicked at 'PANIC'... in the dfx logs.

Given

#[macro_use]
extern crate ic_cdk_macros;

#[update]
fn hello() -> &'static str {
    "Hello World"
}

#[inspect_message]
fn inspect_message() {
    ic_cdk::trap("Trapped!");
}

and

dfx canister call testing hello

I get

Error: The replica returned an HTTP Error: Http Error: status 500 Internal Server Error, content type "", content: Canister rrkah-fqaaa-aaaaa-aaaaq-cai trapped explicitly: Trapped!

Are you on dfx 0.10 / is this observable on mainnet? This may have been recently changed in the replica.

3 Likes

Yes, it appears that dfinity was 1 step ahead of me. I was using dfx v0.9.3. With v0.10 the error message is there as expected. Thank you for you help, @AdamS .

1 Like