amazon-ion / ion-rust

Rust implementation of Amazon Ion
Apache License 2.0
148 stars 36 forks source link

Writer/reader additional context for diagnostic error messages #590

Open jobarr-amzn opened 1 year ago

jobarr-amzn commented 1 year ago

When reviewing a change to ElementStreamWriter I saw this chunk of code: https://github.com/amazon-ion/ion-rust/blob/2fa18ed94e8716fd582cc89683989b64a667cd88/src/element/element_stream_writer.rs#L110-L117

This makes me think about what I would like to see (as a user of this library) if I somehow triggered this case. Right now the error message tells me "some struct value did not have a field name", but which one? How did I get here? A stack trace if presented may be helpful, but some notion of which data is being written or read could be more helpful.

What kind of information would be useful here? We can't "just" dump the local struct-in-progress to the error message, that's likely to be unwieldy or even untenable, and might not even be helpful. I'd suggest that some kind of path expression tracking current context in stream would be useful.

jobarr-amzn commented 1 year ago

I just ran into this again, when ion beta symtab filter from ion-cli aborted with an error message Error: found a non-value in value position.

I can track that error message to header resolution in one of these places:

  1. https://github.com/amazon-ion/ion-rust/blob/42adf2867811dadf09b581081634921d4cd47659/src/binary/non_blocking/raw_binary_reader.rs#L1299
  2. https://github.com/amazon-ion/ion-rust/blob/42adf2867811dadf09b581081634921d4cd47659/src/lazy/binary/immutable_buffer.rs#L615

This doesn't leave me with enough information, though, to narrow down where in 14MB of binary data the problem is.