-
-
Notifications
You must be signed in to change notification settings - Fork 233
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
Make error diagnostics for byte count flags (--skip
, --length
, --display-offset
) awesome
#98
Make error diagnostics for byte count flags (--skip
, --length
, --display-offset
) awesome
#98
Conversation
f758092
to
944f0ff
Compare
…r reporting flexibility This significantly changes the structure of potential output of top-level errors. Before, errors that have a `source` were printed on a single line, with the `source` omitted. Now, an error with a `source` will be printed like: ``` Error: <`Display` impl of error> Caused by: <`Display` impl of `source` error> ``` If there are multiple `source` errors in a chain, then it will be of the form: ``` Error: <`Display` impl of error> Caused by: 0: <`Display` impl of first `source` error> 1: <`Display` impl of `source` of `source` error> # etc. ``` Now, in practice this never happened before, since the only error type that ever could return from `<binary>::run` was `std::io::Error`, which has no `source`. However, `source`s can start being added if, say, future work involved using `anyhow::Context::context` or custom errors that implement `std::Error::source` are added to the codebase. I believe this is a good choice going forward, but I definitely want to foster discussion and acceptance for it in the open first!
27a90a4
to
0ab6c96
Compare
If you are up to it, I'd love to see this. I'm also fine with breaking backwards compatibility (concerning the returned error type). First, it's not like we have tons of reverse dependencies (https://crates.io/crates/hexyl/reverse_dependencies) 😄 and second, I personally never opted into maintaining Thank you very much for this contribution. I will look at the rest of the code soon. |
Found by playing with this:
Can we add a test case for this? |
0ab6c96
to
f84296e
Compare
Oof, regression is embarassing, and lack of test case is embarassing. Fixed. |
f84296e
to
6faa5ab
Compare
Side note, I've implemented |
…actually good This adds an error type called `ByteCountParseError` with a vanilla `std::error::Error` implementation. The code could be significantly compressed with a dependency like `thiserror`. I opted to implement a separate error type for `parse_byte_count` rather than using `anyhow`'s small ecosystem of error types there (though they are used in `<binary>::run`) because it allows pairing diagnostic results with tests, incl. those already written. This can be helpful in preventing regressions in error diagnostics.
6faa5ab
to
3c33ca5
Compare
Thank you very much! |
This PR adds
anyhow
to the codebase, using it as the reporting layer for contextually layered error diagnostics, and then applying those capabilities toparse_byte_offset
. Below are inlined the contents of the commits, since I believe they'll be important for discussion of the design of work here and in the future.This adds an error type called
ByteCountParseError
withthiserror
. I opted to implement a separate error type forparse_byte_count
rather than usinganyhow
's small ecosystem of error types there (though they are used in<binary>::run
) because it allows pairing diagnostic results with tests, incl. those already written. This can be helpful in preventing regressions in error diagnostics.Using
anyhow
with{:?}
is deliberate, and significantly changes the structure of potential output of top-level errors. Before, errors that have asource
were printed on a single line, with thesource
omitted. Now, an error with asource
will be printed like:If there are multiple
source
errors in a chain, then it will be of the form:Now, in practice this never happened before, since the only error type that ever could return from
<binary>::run
wasstd::io::Error
, which has nosource
. However,source
s can start being added if, say, future work involved usinganyhow::Context::context
or custom errors that implementstd::Error::source
are added to the codebase. I believe this is a good choice for error reporting going forward, but I definitely want to foster discussion and acceptance for it in the open first!