Error output in services in .did files from rust canister functions

I want to use service, defined in my .did file:

"deposit_memo" : (FundMem) -> (opt Error);

This method is defined in my canister,

async fn deposit_memo(fundmem: FundMem) -> Option<Error> {
		.deposit_icp_memo(blocktime(), fundmem)

Now, what is important here, is that I simply want to define a generic error output in my .did file.
I know that deposit_icp_memo returns no error.

But in my current code, when I call the service, defining the Error in my .did file as follows:
type Error = nat 8;
type Error = null;
type Error = variant { InvalidInput : text };

there is an output in the function,

deposit_memo output:  FIX ME! opt table1 <: opt Error via special opt rule.
This means the sender and receiver type has diverged, and can cause data loss.

Note that I know that the function completes without error on rust side, so probably I need to specify the Error differently in the .did file? I simply need a very generic error message. Thanks in advance!

I’d recommend you have a look at this solution if you want to experiment with what Rust type turns into which Candid description.

In your specific case, I think it would work if your Rust function is fn my_func() -> Option<String> and you have type Error = text; in your Candid file


I am going to use the export_service macro to find an ideal solution for this. Also, your simple solution works and is manageable in this case.

Thank you very much!

1 Like