-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Labels
backlogThis issue is accepted and assigned to someoneThis issue is accepted and assigned to someonegood first issueGood for newcomersGood for newcomers
Description
Is your feature request related to a problem? Please describe.
This is an issue with @dfinity/candid.
In general, candid decoding errors only throw an error and are not very descriptive.
Example
This is an example of a candid interface with missing variants.
const Service = ({ IDL }: any) =>
IDL.Service({
get_full_neuron: IDL.Func(
[IDL.Nat64],
[IDL.Variant({ Invalid: IDL.Null })],
["query"]
),
});
const agent = new HttpAgent({ host: "https://ic0.app" });
const governance = Actor.createActor(Service, {
agent,
canisterId: "rrkah-fqaaa-aaaaa-aaaaq-cai",
});
(async () => {
await governance.get_full_neuron(1);
})();
This will only throw an error, seemingly without any obvious resolution.
Error: Cannot find field hash _3456837_
at VariantClass.decodeValue (.../@dfinity/candid/src/idl.ts:1018:11)
Describe the solution you'd like
One way to improve errors is to print the raw candid response along with our type:
Error: Unexpected field hash _3456837_. Did you forget to include a variant?
Received raw candid:
[
{
"_3456837_": {
"_1389388560_": "",
"_3790638545_": 3
}
}
]
Provided type:
variant {Invalid:null}
Metadata
Metadata
Assignees
Labels
backlogThis issue is accepted and assigned to someoneThis issue is accepted and assigned to someonegood first issueGood for newcomersGood for newcomers