Comments (3)
The error-chain is my favorite feature in error-chain
.
I remember rustup
failing to download a file from behind the company's proxy and instead of getting the usual misleading error: No such file or directory
, I got a very clear chain of errors explaining that:
- It failed to access the link
- Because it failed to access the link, it failed to download the file
- Because it failed to download the file, it does not exist
It made it extremely easy for me to fix the root cause.
Edit(the rustup output when I remove the SOCKS4 proxy):
error: could not download file from 'https://static.rust-lang.org/rustup/release-stable.toml' to '/tmp/rustup-update.T7Ry8gjuIytx/release-stable.toml'
info: caused by: error during download
info: caused by: [7] Couldn't connect to server (Failed to receive SOCKS4 connect request ack.)
from failure.
For reference, with #54 here is an approximation (meaning I haven't built it) of error-chain:
// Decide which command to run, and run it, and print any errors.
if let Err(err) = run(&args) {
let mut stderr = io::stderr();
let mut causes = err.causes();
writeln!(stderr, "Error: {}", causes.next().expect("`causes` to at least contain `err`"))
.expect("unable to write error to stderr");
for cause in causes {
writeln!(stderr, "Caused by: {}", cause)
.expect("unable to write error to stderr");
}
// The following assumes an `Error`, use `if let Some(backtrace) ...` for a `Fail`
writeln!(stderr, "{:?}", backtrace)
.expect("unable to write error to stderr");
process::exit(1);
}
from failure.
I've just merged #54, which implements a causes iterator. I think something like this would be adequate for your use case for now:
let mut stderr = io::stderr();
for fail in err.causes() {
let _ = writeln!(stderr, "{}", fail);
}
from failure.
Related Issues (20)
- Addition of name member to Fail trait is a semver-breaking change HOT 4
- Should `backtrace` dependency be optional? HOT 1
- Compat should override method source() HOT 1
- Repository field for `failure_derive` and `failure` do not match HOT 1
- Support for an alloc feature? HOT 1
- failure-v0.1.5 fails to compile with rustc-1.37.0 HOT 6
- Add option to derive Debug identical to Display HOT 1
- Collaborate on a "core::Error" crate with snafu, anyhow and other error crates HOT 1
- Update failure_derive dependencies HOT 1
- support `at` method using for locate error
- Move Repository To rust-lang HOT 7
- Fix guide example code
- Memory safe violation by abusing `__private_get_type_id__` HOT 1
- Propagate never type
- error: /lib64/libc.so.6: version `GLIBC_2.18' not found HOT 2
- 'backtrace' is forcing an increased MinSRV; pin 'backtrace' to `version = "<= 0.3.30"` HOT 6
- [FEATURE REQUEST] Add ability to `bail!` and `ensure!` error types.
- failure_derive won't build with quote 1.0.3 HOT 16
- Why does this exist? HOT 2
- "trailing semicolons in expression macro bodies" breaks with bail
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from failure.