sharkdp / hexyl

A command-line hex viewer
Apache License 2.0
8.92k stars 227 forks source link

Print error message if parsing of --length/--skip/… fails #97

Closed sharkdp closed 4 years ago

sharkdp commented 4 years ago

We should print an error if the parsing of the size argument for --length, --skip, … fails. Currently, we silently ignore the argument:

▶ echo 12345 | hexyl --skip 2b   
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000002│ 33 34 35 0a             ┊                         │345_    ┊        │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

~                                                                                                       
▶ echo 12345 | hexyl --skip 2byte
┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐
│00000000│ 31 32 33 34 35 0a       ┊                         │12345_  ┊        │
└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘

I'd prefer if we use anyhow for error handling (if we want to rely on a library at all).

If we want to have good error messages, we probably want to modify

fn parse_byte_count(n: &str, block_size: PositiveI64) -> Option<PositiveI64>

to return a Result<PositiveI64> with several possible error paths.

sharkdp commented 4 years ago

this has actually already been brought up by @ErichDonGubler here: https://github.com/sharkdp/hexyl/issues/44#issuecomment-634105599

ErichDonGubler commented 4 years ago

If you want to assign this to me, I'm more than happy to take it. anyhow is an easy way to add some simple error handling, and this should be fast. :)

sharkdp commented 4 years ago

If you want to assign this to me, I'm more than happy to take it

:+1:

ErichDonGubler commented 4 years ago

How's this issue looking? I believe we handled the missing error diagnostics for parse failures here.

sharkdp commented 4 years ago

Absolutely. Forgot to close it. Thanks!