chmln / handlr

A better xdg-utils
MIT License
608 stars 24 forks source link

panic when mimeapps.list doesn't end with newline? #52

Open ghost opened 2 years ago

ghost commented 2 years ago

Thanks for this excellent piece of software.

Version: 0.6.4

When my mimeapps.list doesn't end with a newline I get this panic:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseApps(Error { variant: ParsingError { positives: [value_char], negatives: [] }, location: Pos(308), line_col: Pos((11, 22)), path: None, line: "text/*=emacs.desktop;", continued_line: None })', src/apps/user.rs:12:65
stack backtrace:
   0:     0x55eac2c5c82e - <unknown>
   1:     0x55eac2bfd04c - <unknown>
   2:     0x55eac2c5bf64 - <unknown>
   3:     0x55eac2c5bd9d - <unknown>
   4:     0x55eac2c7a108 - <unknown>
   5:     0x55eac2c7a086 - <unknown>
   6:     0x55eac2c7a042 - <unknown>
   7:     0x55eac2b82210 - <unknown>
   8:     0x55eac2b824f2 - <unknown>
   9:     0x55eac2b90b96 - <unknown>
  10:     0x55eac2c3155b - <unknown>
  11:     0x55eac2c52658 - <unknown>
  12:     0x55eac2b87aab - <unknown>
  13:     0x55eac2c0fe53 - <unknown>
  14:     0x55eac2c0b693 - <unknown>
  15:     0x55eac2c0ddc3 - <unknown>
  16:     0x7fc3d22e2b25 - __libc_start_main
  17:     0x55eac2b8cbbe - <unknown>
  18:                0x0 - <unknown>

When I add a newline, there is no issue.

I think handlr should throw an error here or ignore it.

Lehmanator commented 7 months ago

Getting a similar issue when an entry in mimeapps.list doesn't have a string on the right-hand side of the =.

$ handlr get x-scheme-handler/matrix

thread 'main' panicked at src/apps/user.rs:12:65:
called `Result::unwrap()` on an `Err` value: ParseApps(Error { variant: ParsingError { positives: [value_char], negatives: [] }, location: Pos(121), line_col: Pos((5, 12)), path: None, line: "audio/mpeg=␊", continued_line: None })
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: core::ops::function::FnOnce::call_once
   4: once_cell::imp::OnceCell<T>::initialize::{{closure}}
   5: once_cell::imp::initialize_inner
   6: once_cell::imp::OnceCell<T>::initialize
   7: handlr::main

This was on NixOS where my user ~/.config/mimeapps.list had some entries lines with no app on the right hand side of the association. Removing the empty entries fixed this for me.

Not sure if lines without the assignment argument are valid in the mimetypes.list spec, but handlr should probably report the malformed file & line number instead of panic.