Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages for candid decoding errors #470

Open
FloorLamp opened this issue Jul 16, 2021 · 1 comment
Open

Improve error messages for candid decoding errors #470

FloorLamp opened this issue Jul 16, 2021 · 1 comment
Assignees
Labels
backlog This issue is accepted and assigned to someone good first issue Good for newcomers

Comments

@FloorLamp
Copy link
Contributor

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}
@krpeacock
Copy link
Contributor

Thanks, this seems reasonably scoped! I'll add it to my backlog

@krpeacock krpeacock self-assigned this Oct 28, 2021
@krpeacock krpeacock added good first issue Good for newcomers backlog This issue is accepted and assigned to someone labels Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog This issue is accepted and assigned to someone good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants