desbma / rsop

Simple, fast & configurable tool to open and preview files
MIT License
22 stars 3 forks source link

Panics when path doesn't exist #1

Closed keith-hall closed 2 years ago

keith-hall commented 2 years ago

Hi,

Thanks for this great tool!

I noticed that it currently panics when passing a path which doesn't exist. And also when the relevant handler_preview command doesn't exist (and shell is false). Currently both scenarios look the same from a user perspective which was confusing for me.

RUST_BACKTRACE=full rsp ./noexist
Backtrace (most recent call first):
  File "/build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c", line 308, in __libc_start_main

The application panicked (crashed).
  called `Result::unwrap()` on an `Err` value: No such file or directory (os error 2)
in src/main.rs, line 105
thread: main

It would be nice if it just showed a simple (but descriptive) error instead of panicking. (While keeping the exit/return code to indicate failure.) Perhaps something similar to bats approach: image

desbma commented 2 years ago

Yes I agree the error handling is not user friendly.

desbma commented 2 years ago

It should be fixed in 9a07d59ee21f2ba1a01e380df9703e3df91f0eba, please test.

keith-hall commented 2 years ago

Nice, much more user-friendly now - thank you!

Do you think it's worth mentioning which handler failed to start? So instead of:

❯ rsp Cargo.toml 
ERROR [rsop] Failed to start handler: No such file or directory (os error 2)

it could say something like:

ERROR [rsop] Failed to start "handler_preview" for filetype "text": No such file or directory (os error 2)

if so, I could try to work on a PR for that if you want to save you the trouble/time :)

keith-hall commented 2 years ago

And I think the exit code still isn't set on failure:

❯ rsp noexist.txt
ERROR [rsop] Failed to read input file or data: No such file or directory (os error 2)
❯ echo $?
0

I think it should set it to a non-zero value like 1 when something goes wrong. I'd be happy to look at making a PR for this too :)

desbma commented 2 years ago

I have made some more improvements in f1f558c45994d4fc48b4c05d7e40cc2c3b59020d.

keith-hall commented 2 years ago

Wow, this is amazing - thank you so much! :D I consider this issue resolved :)