AgentJs Candid Pinpointed Type Errors upgrade - PR

I often stumble upon horrible Candid errors which take up to 1 hour to figure.

For me personally, that’s one of the worst parts of the dev experience, so now that I know how things work better, I went and fixed it.

When it occurs: Writing dapps with agentjs, using nested structures in your calls, and not providing correct input.

Before: You basically get the whole record dumped with no specific reason given

Pull Request:
Errors look like this now:

[Error: Invalid record {arg:vec nat8; wasm_module:vec nat8; mode:variant {reinstall; upgrade; install}; canister_id:principal} argument: 

field canister_id -> Invalid principal argument: "rrkah-fqaaa-aaaaa-aaaaq-cai"]
  1. It follows the nested structure and chains thrown errors, so no matter how deep you go, you will see where the problem is - pinpointed.
  2. Cuts long values (you don’t want a 2mb blob inside your error)
  3. Works with the current tests and shouldn’t introduce breaking changes

Thanks for taking the time to write this up. Definitely not great experience. Let me ping folks who may know more so they are aware.

1 Like

Maybe it’s not that bad for Typescript users, since they should be getting type errors. And perhaps that’s why it was under the radar.