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

Links and custom description / display #123

Open
theduke opened this Issue Feb 7, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@theduke
Copy link

theduke commented Feb 7, 2017

One thing I really dislike about error_chain compared to quick_error is the inability to add a custom description and format to foreign_link errors (and regular links as well, actually).

The docs suggest using chain_err, but this looses the type information for the cause, which is not ideal, and you have to implement From manually.

Any plans to add that functionality?

error_chain! {
    foreign_links {
        Io(e: ::std::io::Error) {
            description("disk_io")
            display("Could not read/write from disk: '{}'", e)
        }
    }
}

@theduke theduke changed the title Foreign links and custom description / display Links and custom description / display Feb 7, 2017

@theduke

This comment has been minimized.

Copy link
Author

theduke commented Feb 7, 2017

Upon investigation, you can get almost the described behaviour:

error_chain! {
  errors {
    Io(e: io::Error) {
      description(..)
      display(..)
      cause(&e)
      from()
    }
  }
}

The only thing missing is, this only gives a From implementation for io::Error to ErrorKind, and you need to implement From manually.

@Arnavion

This comment has been minimized.

Copy link

Arnavion commented Feb 7, 2017

cause() and from() don't do anything in error-chain. You can remove them.

>you need to implement From manually.

Why do you need to implement manually? If you're talking about an impl for io::Error -> Error, it's unnecessary since impls for io::Error -> ErrorKind and ErrorKind -> Error are already generated.

Edit: Sorry, I misread that you switched to using custom links in your second post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.