Fail to decode argument 0 from table0 to variant { Ok : nat; Err : text }

I have two canisters, one (in Rust) of which sends a request to another (in Motoko, I don’t have source code for that canister, only types).
The response has Motoko type Result.Result<Nat, Text>, so at the Rust side I’m using the following code:

    async fn call_test_method(canister_id: Principal) -> CallResult<(Result<Nat, String>,)> {
        call(canister_id, "test_method", ()).await
    }

Execution of this function leads to the following error message:

The Replica returned an error: code 5, message: "Canister knhk5-cyaaa-aaaak-aagoq-cai trapped explicitly: Custom(Fail to decode argument 0 from table0 to variant { Ok : nat; Err : text }

Caused by:
    0: input: 4449444c016b029cc2017de58eb402710100_0124736c6970706167653a20696e73756666696369656e74206f757470757420616d6f756e74
       table: type table0 = variant { 24_860 : nat; 5_048_165 : text }
       wire_type: table0, expect_type: variant { Ok : nat; Err : text }
    1: table0 is not a subtype of variant { Ok : nat; Err : text }
    2: Variant field 24_860 not found in the expected type)"

test_method() executes successfully, it seems like there is only a decoding issue.
As I can tell, types variant { 24_860 : nat; 5_048_165 : text } and variant { Ok : nat; Err : text } are the same, but the error is there for some reason.

What should I do? I’m on dfx 0.8.4 and cdk-rs 0.3.3. The whole thing happens on main-net.

@chenyan

Very likely a mismatch between rust’s Result which uses Ok and Err, and Motoko’s Result, which uses ok and err.

4 Likes

This should be illegal.
Thanks a lot!

2 Likes

7 Likes

Any scheduled sprint for a fix? Not sure this topic should be denoted as ‘solved’.

I went thru the tutorial @senior.joinu (and BTW , brilliant!).

'and Result type in Motoko is not compatible with the same Result type in Rust. This is why we need … some kind of function to transform Motoko’s Result into Rust’s Result’

1 Like