TaKO8Ki / frum

A little bit fast and modern Ruby version manager written in Rust
MIT License
636 stars 15 forks source link

Don't panic, return error #103

Open kenoss opened 3 years ago

kenoss commented 3 years ago

I think the following error is not user-friendly.

$ RUST_BACKTRACE=1 cargo run install hoge
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/frum install hoge`
thread 'main' panicked at 'internal error: entered unreachable code', src/version.rs:33:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:50:5
   3: frum::version::Version::parse
             at ./src/version.rs:33:13
   4: <frum::input_version::InputVersion as core::str::traits::FromStr>::from_str
             at ./src/input_version.rs:47:15
   5: frum::main::{{closure}}
             at ./src/main.rs:58:21
   6: core::option::Option<T>::map
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/option.rs:823:29
   7: frum::main
             at ./src/main.rs:57:26
   8: core::ops::function::FnOnce::call_once
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I found at least two not-good points of error handling of this repository.

I recommend you to use eyre and color-eyre. See https://github.com/yaahc/color-eyre/blob/master/examples/usage.rs and try to run. (eyre is a fork of anyhow and I think eyre suits CLI programs because it has additional features like suggestion.)

kenoss commented 3 years ago

Note that you can mix thiserror and eyre.