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

Allow Context to wrap Fail implementations #60

Closed
epage opened this issue Nov 18, 2017 · 2 comments
Closed

Allow Context to wrap Fail implementations #60

epage opened this issue Nov 18, 2017 · 2 comments

Comments

@epage
Copy link

epage commented Nov 18, 2017

Moving this from reddit.

Context can either be a cheaply constructed Fail or an extension to Error. It doesn't allow wrapping a struct that implements Fail.

This was more understandable when it felt like the focus was exclusively on using Error but now with the emphasis being on there being multiple workflows, this seems like shortcoming in the API.

@epage
Copy link
Author

epage commented Nov 18, 2017

Naively, it'd be great to just make Context generic over a Fail. The problem is that Error isn't a Fail because of coherence problems.

Without resolving the coherence problem, either by waiting to break the API once specialization is available or by removing the From<Fail> for Error, this would probably require expanding the Either enum to a generic Fail. The problem with that is that Context would then have a useless generic parameter when used with Error.

@withoutboats
Copy link
Contributor

This is an intentional design choice. The value of Context largely comes from the fact that you can wrap multiple kinds of errors together. If it had a parameter, this would not be true. Apologies for not explaining in more detail, but I explored down this path and found it added a lot of complexity to the APIs and to the recommended Error + ErrorKind pattern.

In contrast, if all you want to do is add some displayable info to a particular error type, the wrapper for that is not very difficult to write.

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