Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't panic, return error #103

Open
kenoss opened this issue Sep 19, 2021 · 1 comment
Open

Don't panic, return error #103

kenoss opened this issue Sep 19, 2021 · 1 comment

Comments

@kenoss
Copy link
Contributor

kenoss commented Sep 19, 2021

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
Copy link
Contributor Author

kenoss commented Sep 19, 2021

Note that you can mix thiserror and eyre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant