IC0406 CanisterReject Error on Update Calls When Using inspect_message

I am facing an issue where every update call to my canister gets rejected with the error:

The replica returned a rejection error: reject code CanisterReject, reject message Error from Canister avqkn-guaaa-aaaaa-qaaea-cai: Canister rejected the message, error code Some(“IC0406”)

This happens after I added an inspect_message function to block certain method calls. Below is my implementation of inspect_message:

#[ic_cdk::inspect_message]
fn inspect_message() {
    let method_name = ic_cdk::api::call::method_name();
    ic_cdk::println!("Inspecting method call: {}", method_name);

    if method_name == "faucet" {
        ic_cdk::println!("Execution blocked! User has reached the limit.");
        ic_cdk::api::call::reject("Limit reached: Cannot click more than 5 times.");
    } else {
        ic_cdk::println!("Execution allowed for {}", method_name);
    }
}

However, after deploying this, all update calls fail, even the ones that should be allowed. For example, calling my simple update function and other update functions as well.

#[update]
pub fn think() {
    ic_cdk::println!("i think ");
}

In the provided example I don’t see any calls of ic0.accept_message() meaning every inspect_message call does not accept any message. Can this be the reason for that error?

In ic_cdk it should be ic_cdk::api::call::accept_message, see accept_message in ic_cdk::api::call - Rust

1 Like

Yes, you are right i was not able to figure it out the use of the accept message, now things are working fine by the way.

1 Like