joshuto icon indicating copy to clipboard operation
joshuto copied to clipboard

Joshuto crashes when the preview script returns binary rubish

Open DLFW opened this issue 4 years ago • 4 comments

I accidentially put a cat $path in my preview.sh for image formats when I wanted to test something, so preview.sh returned cat's output for a binary file. If that happens, Joshuto just crashes.

Of course, a user should take care that the preview script returns only sensible text, but Joshuto should handle this more gracefully and maybe give the user a hint about what went wrong.

DLFW avatar Dec 20 '21 22:12 DLFW

Could you provide the error message?

RUST_BACKTRACE=1 joshuto 2>output.log

kamiyaa avatar Dec 20 '21 23:12 kamiyaa

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/daniel/.cargo/registry/src/github.com-1ecc6299db9ec823/ansi-to-tui-0.4.1/src/ansi.rs:69:39
stack backtrace:
   0: rust_begin_unwind
             at /rustc/0035d9dcecee49d1f7349932bfa52c05a6f83641/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/0035d9dcecee49d1f7349932bfa52c05a6f83641/library/core/src/panicking.rs:93:14
   2: core::panicking::panic
             at /rustc/0035d9dcecee49d1f7349932bfa52c05a6f83641/library/core/src/panicking.rs:50:5
   3: core::option::Option<T>::unwrap
             at /rustc/0035d9dcecee49d1f7349932bfa52c05a6f83641/library/core/src/option.rs:735:21
   4: ansi_to_tui::ansi::ansi_to_text
             at /home/daniel/.cargo/registry/src/github.com-1ecc6299db9ec823/ansi-to-tui-0.4.1/src/ansi.rs:69:21
   5: <joshuto::ui::widgets::tui_file_preview::TuiFilePreview as tui::widgets::Widget>::render
             at /home/daniel/sandbox/joshuto_2/src/ui/widgets/tui_file_preview.rs:23:26
   6: <joshuto::ui::views::tui_folder_view::TuiFolderView as tui::widgets::Widget>::render
             at /home/daniel/sandbox/joshuto_2/src/ui/views/tui_folder_view.rs:173:25
   7: <joshuto::ui::views::tui_view::TuiView as tui::widgets::Widget>::render
             at /home/daniel/sandbox/joshuto_2/src/ui/views/tui_view.rs:24:9
   8: tui::terminal::Frame<B>::render_widget
             at /home/daniel/.cargo/registry/src/github.com-1ecc6299db9ec823/tui-0.16.0/src/terminal.rs:103:9
   9: joshuto::ui::tui_backend::TuiBackend::render::{{closure}}
             at /home/daniel/sandbox/joshuto_2/src/ui/tui_backend.rs:68:13
  10: tui::terminal::Terminal<B>::draw
             at /home/daniel/.cargo/registry/src/github.com-1ecc6299db9ec823/tui-0.16.0/src/terminal.rs:267:9
  11: joshuto::ui::tui_backend::TuiBackend::render
             at /home/daniel/sandbox/joshuto_2/src/ui/tui_backend.rs:66:17
  12: joshuto::run::run
             at /home/daniel/sandbox/joshuto_2/src/run.rs:31:9
  13: joshuto::run_joshuto
             at /home/daniel/sandbox/joshuto_2/src/main.rs:108:9
  14: joshuto::main
             at /home/daniel/sandbox/joshuto_2/src/main.rs:149:21
  15: core::ops::function::FnOnce::call_once
             at /rustc/0035d9dcecee49d1f7349932bfa52c05a6f83641/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Seems ansi-to-tui unwraps an error when doing some syntax parsing or similar. Seems to be reproducible at least when cating GIF files.

DLFW avatar Dec 21 '21 00:12 DLFW

Fixed via 8bae4a1ceda7dd7f4c603b736403322a0c37c3a0

However, the new ansi-to-tui doesn't seem to be parsing ansi text correctly. So I will keep this open until that is fixed.

See: https://github.com/uttarayan21/ansi-to-tui/issues/10

kamiyaa avatar Dec 28 '21 14:12 kamiyaa

I tested this again with the new ansi-to-tui dependency. When cat-ing a binary, just nothing is shown in Joshuto's preview pane, and no error message is shown either.

I guess ansi-to-tui does not return an error when it gets invalid input, so we can't handle the problem in the application (by showing an errror msg). Anyway, I guess we can close this. :smile:

DLFW avatar Jun 18 '22 21:06 DLFW