GithubHelp home page GithubHelp logo

Comments (3)

lilianmoraru avatar lilianmoraru commented on June 27, 2024 4

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:

  1. It failed to access the link
  2. Because it failed to access the link, it failed to download the file
  3. 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.

epage avatar epage commented on June 27, 2024 1

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.

withoutboats avatar withoutboats commented on June 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.