GithubHelp home page GithubHelp logo

Comments (7)

Yamakaky avatar Yamakaky commented on August 29, 2024 1

Do you want to try a PR?

from error-chain.

golddranks avatar golddranks commented on August 29, 2024

So, I tried and made two additional APIs. My work is here: golddranks@76d5ccf

I added a CausedErr trait that is analogous to ChainErr, but works directly on types implementing the std::error::Error trait, not Result. With that, I was able to get the ugly

e => Err::<(), diesel::result::Error>(e).chain_err(|| "Error when trying to retrieve user!").unwrap_err(),

row to

e => e.caused_err(|| "Error when trying to retrieve user!"),

I could also refactor the implementation of ChainErr to use that. (Just basic DRY)

I also added a .to_err() helper method for ErrorKind, which works exactly like .into() but causes less problems with type inference. (Basically it's but a sugar to Error::from(), but I like the conciseness, method syntax and lack of :: better.)

Still WIP in the sense that I haven't touched the docs. But what do you think about these changes? Do they seem worthwile, @brson ? Shall I send a PR?

from error-chain.

Yamakaky avatar Yamakaky commented on August 29, 2024

It seems close to cause() from https://github.com/tailhook/quick-error?
Edit: not really...

from error-chain.

Yamakaky avatar Yamakaky commented on August 29, 2024

@golddranks please review #62

from error-chain.

TedDriggs avatar TedDriggs commented on August 29, 2024

I see the PR for this has stalled due to an inference problem; are there any plans to revive it?

FWIW, I hit the exact same issue (also when using map_err) and found that this was sufficient to get moving again:

impl Error {
    pub fn caused<K: Into<ErrorKind>>(self, kind: K) -> Self {
        Error::with_chain(self, kind)
    }
}

Would a simple approach like that work for this?

from error-chain.

TedDriggs avatar TedDriggs commented on August 29, 2024

Since #141 was merged, should this be closed?

from error-chain.

golddranks avatar golddranks commented on August 29, 2024

Indeed! Thanks!

from error-chain.

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.