candid
candid copied to clipboard
As a user, I want to see more context for deserialization errors so that debugging is faster
Is your feature request related to a problem? Please describe. An example candid deserialization error message is: "No more values to deserialize". That can be hard to debug: what I want to know is:
- The full context -- that is the full sequence of bytes that were being deserialized.
- Why was a value expected? In other words, what part of the candid type is missing?
Describe the solution you'd like
I'd like something like:
"No more value to deserialize. While trying to deserialize
Describe alternatives you've considered I have none.
Additional context
There's a rudimentary debug info here: https://github.com/dfinity/candid/blob/master/rust/candid/src/de.rs#L127. It is in the error structure, but not displayed at the moment. I can recover that before we have a better debug message.
@chenyan-dfinity Sounds great!
@sasa-tomic pointed me to https://github.com/dfinity/bigmap-rs/blob/master/vendor/rust-cdk/src/ic_cdk/src/api/context.rs#L103-L119
CC @bitdivine
@chenyan-dfinity, @hansl and others: can we get this bug prioritized?
For instance, @bitdivine is complaining, with merit I think, that in case of "type mismatch", the error message does not contain the field name that caused the mismatch to happen.
Thank you for pointing out this PR. Indeed, I have:
+ dfx --identity bootstrap-super-leader canister --network=bootstrap_bootstrap call \
governance forward_vote '(49, 3, variant{Yes})'
The Replica returned an error: code 5, message: "Canister rrkah-fqaaa-aaaaa-aaaaq-cai \
trapped explicitly: Panicked at 'Deserialization Failed: "Deserialize error: Type mismatch. \
Type on the wire: Int; Expected type: Nat64"', /source/source/src/endpoint.rs:34:21"
(I have added line breaks for readability)
with a fully up-to-date did file. I have no idea what the problem is or how to fix it.
Yes, we are improving the error message as we add subtyping check in deserialization.
For @bitdivine's case, it seems dfx
is not getting the did file. Is governance.did specified in dfx.json
? If the did file is missing, you need type annotations for nat64
, so the argument would be (49: nat64, 3: nat64, variant{Yes})
. The annotation is not needed when dfx can fetch the correct did file.