-
Notifications
You must be signed in to change notification settings - Fork 98
Description
Describe the bug
When using the JS agent to make requests to Rust canisters methods that return null, the agent throws the error: Wrong number of return values.
To Reproduce
- Create a new rust canister using dfx:
dfx new --type=rust actor_test - Enter the directory:
cd actor_test - Update the canister's lib.rs file to contain one method that returns the unit type (which according to the candid reference is the equivalent of motoko's
Nulltype):#[ic_cdk_macros::query] fn get_null() -> () { return (); }
- Update the candid file to match:
service : { "get_null": () -> (null) query; } - Start up the replica:
dfx start - Deploy the canister:
dfx deploy - Open the generated candid UI website in your browser (likely at http://127.0.0.1:8000/?canisterId=r7inp-6aaaa-aaaaa-aaabq-cai&id=rrkah-fqaaa-aaaaa-aaaaq-cai)
- Open the dev tools to see the console output
- Click the "QUERY" button in the UI to initiate a call to the
get_nullcanister method - Note that the error message "Wrong number of return values" is displayed in the UI and in the console.
- Make the equivalent call using DFX and note that there aren't any problems:
dfx canister call actor_test get_null=>(null: null)
Expected behavior
The agent should handle the null return value instead of throwing an error, and both the call and the result (null) should be displayed in the output log in the Candid UI.
Desktop (please complete the following information):
- OS: Ubuntu 21.10
- Browser: Brave
- Version: Version 1.39.111 Chromium: 102.0.5005.61 (Official Build) (64-bit)
Additional context
This is only a problem for Rust and Azle canisters. The agent handles null responses from Motoko canisters without problem. For example, consider the following Motoko canister:
actor ActorTest {
public query func get_null(): async Null {
return null;
};
}The candid file for both this motoko canister and the provided Rust canister are the same, namely:
service : {
"get_null": () -> (null) query;
}
Therefore, it should be that the the agent can handle both canisters the same. However, only the null value being returned by the Motoko canister is correctly handled by the JS Agent.
Also worth noting is that although the JS Agent doesn't handle the Rust return values, both canisters return (null: null) when executing dfx canister call agent_test get_null from the command line.

