Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Links and custom description / display #123

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

Links and custom description / display #123

theduke opened this issue Feb 7, 2017 · 2 comments

Comments

@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
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
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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants