mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-30 09:05:54 +00:00
Better error message when seek fails
> hexyl "$(which hexyl)" --skip=-5gib
Error: Failed to jump to the desired input position. This could be
caused by a negative offset that is too large or by an input that is not
seek-able (e.g. if the input comes from a pipe).
ref: #114
This commit is contained in:
1 parent
66f8508b57
commit
8c3f2230c6
4 files changed
+119
-7
No files matched your search
+14
-6
@@ -150,12 +150,20 @@ fn run() -> Result<(), AnyhowError> {
|
||||
|
||||
let skip_offset = if let Some(ByteOffset { kind, value }) = skip_arg {
|
||||
let value = value.into_inner();
|
||||
reader.seek(match kind {
|
||||
ByteOffsetKind::ForwardFromBeginning | ByteOffsetKind::ForwardFromLastOffset => {
|
||||
SeekFrom::Current(value)
|
||||
}
|
||||
ByteOffsetKind::BackwardFromEnd => SeekFrom::End(value.checked_neg().unwrap()),
|
||||
})?
|
||||
reader
|
||||
.seek(match kind {
|
||||
ByteOffsetKind::ForwardFromBeginning | ByteOffsetKind::ForwardFromLastOffset => {
|
||||
SeekFrom::Current(value)
|
||||
}
|
||||
ByteOffsetKind::BackwardFromEnd => SeekFrom::End(value.checked_neg().unwrap()),
|
||||
})
|
||||
.map_err(|_| {
|
||||
anyhow!(
|
||||
"Failed to jump to the desired input position. \
|
||||
This could be caused by a negative offset that is too large or by \
|
||||
an input that is not seek-able (e.g. if the input comes from a pipe)."
|
||||
)
|
||||
})?
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user