candid icon indicating copy to clipboard operation
candid copied to clipboard

As a user, I want to see more context for deserialization errors so that debugging is faster

Open luc-mercier opened this issue 4 years ago • 7 comments

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 into a <name of the CandidType>, the end of the byte stream was reached, but a was expected."

Describe alternatives you've considered I have none.

Additional context

luc-mercier avatar Oct 22 '20 14:10 luc-mercier

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 avatar Oct 22 '20 16:10 chenyan-dfinity

@chenyan-dfinity Sounds great!

luc-mercier avatar Oct 22 '20 17:10 luc-mercier

@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

luc-mercier avatar Oct 23 '20 09:10 luc-mercier

CC @bitdivine

luc-mercier avatar Mar 22 '21 12:03 luc-mercier

@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.

luc-mercier avatar Mar 22 '21 12:03 luc-mercier

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.

bitdivine avatar Mar 22 '21 12:03 bitdivine

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.

chenyan-dfinity avatar Mar 22 '21 16:03 chenyan-dfinity