Canister xxx trapped explicitly: IDL error: empty input

Hi
I am getting the following error, anyone knows what it means?
‘Canister xxx trapped explicitly : IDL error: empty input’

I am calling the below query method in canister using agent library.

var a : Text = "first, ";
public shared query func greet() : async Text {
        "Hello, " # a # "!";
};

like this :

	const queryData = {

        methodName : 'greet',

look at second comment for arg parameter as I could not post here for some reason

    }

    agent.query...

arg : blobFromUint32Array ( new Uint32Array() )

1 Like

Canisters expect arguments encoded in Candid, and it seems you programmed your client to send zero bytes as the argument. I don’t know the JS side of things well, but you need to candid encode your argument.

Motoko could give a better error message here though, “expected Candid-encoded argument, but received a zero-length argument” maybe. Nice beginner issue for aspiring Motoko contributers?

1 Like

Thank you. One thing I don’t understand is the method expects no input parameters. What is a candid encode argument for no parameters?

I created this pull request with the edit:
Updated error message for empty input by ehsan6sha · Pull Request #2665 · dfinity/motoko (github.com)

The empty argument sequence is encoded as DIDL\0\0, but if you use the agent as intended this should be taken care of for you

1 Like