[Suggestion] Consider using error-chain to bubble up errors rather than panicking
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
AFAIK, error-chain is one of the easiest way to handle errors in an application. Check its docs: add an errors module with a macro in it and then just try! / ? all your results. No boilerplate.
What it doesn't do for you printing the errors to stderr though. I particularly use this code to get an output that's like rustup error messages. This way RUST_BACKTRACE can be used to get backtraces about errors.
Example
$ RUST_BACKTRACE=1 xargo build --target thumbv7em-none-eabihf
error: not inside a Cargo project
stack backtrace:
0: 0x55cc7113d46d - backtrace::backtrace::trace::h16372ee7bf1517e5
1: 0x55cc7113daf2 - backtrace::capture::Backtrace::new::hcc43c50c4b11c693
2: 0x55cc7113d028 - error_chain::make_backtrace::hc1426b5ba6934a5a
3: 0x55cc71112fb0 - xargo::sysroot::update_target_sysroot::hd155023c5732e068
4: 0x55cc7111a227 - xargo::run::hb57f90fc28e742fe
5: 0x55cc7111714d - xargo::main::h2ea2ba11333d01ee
6: 0x55cc71161ada - panic_unwind::__rust_maybe_catch_panic
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libpanic_unwind/lib.rs:97
7: 0x55cc711593e5 - std::panicking::try<(),fn()>
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panicking.rs:332
- std::panic::catch_unwind<fn(),()>
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/panic.rs:351
- std::rt::lang_start
at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/../src/libstd/rt.rs:57
8: 0x7ff4dc8c5290 - __libc_start_main
9: 0x55cc710ffa79 - _start
10: 0x0 - <unknown>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no cargo-sym files or tests; begin by locating the CLI entry point and current panic sites. Compare the linked xargo src/main.rs example and the proposed errors module, then assess replacing result panics with error-chain propagation and stderr output with optional RUST_BACKTRACE support. Done means failures report readable errors without panicking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100