Anything that is not checked off still needs your help! There is no need to sign up or ask for permission - follow any of these links and leave your thoughts:
Guidelines checklist
Legend
[y] = guideline is adhered to, no work needed.
[n] = guideline may need work, see comments nearby
This document is collaboratively editable. Pick a few of the guidelines, compare the error-chain crate against them, and fill in the checklist with [y] if the crate conforms to the guideline, [n] if the crate does not conform, and [/] if the guideline does not apply to this crate. Each guideline is explained in more detail here. If [n], please add a brief note on the following line with an explanation. For example:
- [n] Crate name is a palindrome (C-PALINDROME)
- error-chain backwards is niahc-rorre which is not the same as error-chain
Come up with ideas for nice introductory examples of using error-chain, possibly in combination with other crates, that would be good to show in the Rust Cookbook. Please leave a comment in that issue with your ideas! You donāt necessarily have to write the example code yourself but PRs are always welcome.
error-chain is definitely oriented towards getting started quickly writing apps, but it isnāt obviously wrong for libs to use error-chain. Should it be explicitly recommended either way?
Design compromises around links / foreign links
When and how to enable backtraces
This has been iterated on a lot and has performance implications
Structural typing between ālinksā in from conversions
The names ālinksā and āforeign linksā are not fully evocative of the crucial distinction: whether chaining occurs
Itād be good to dive more deeply into the rationale for this precise split.
(brson) links allow for deep matching on chained error types and backtrace-propagation
because they follow the error-chain āprotocolā. Their From conversions
pass the backtrace between each other, while building up a nested
enum for the ErrorKind.
(brson) foreign_links do not follow the error-chain protocol and can do neither
of these things
What are the pros/cons of locally defining Error and ResultExt?
It seems like links could be simplified if Errors were just type aliases
(brson) I doubt it is possible to formulate it in such a way because of coherence issues. I did try. The ResultExt trait that defines chain_err is defined in terms of the local ErrorKind. The inability to define a single ChainedError type and need to define so many local types is pretty much the reason the error-chain crate is one massive macro.
Error derefs to ErrorKind, how do we feel about that?
(brson) seems like an abuse of Deref
Msg(String) always being a variant, with conversions ā worth talking about
This may be one aspect that separates libs from apps
error_chain, error_chain_processed and quick_error ā can these be hidden?
(brson) not error_chain surely
(brson) istm everything but error_chain and quick_main should be hidden and follow some convention for hidden macros
Possible discussion piece: I noticed that when using quick_run!, and it printed out the cause trace for an error that was returned, it can show duplicated messages depending on the implementation of the errors. This happens with reqwest, but see this small example:
This isnāt really error-chains fault, itās just following the chain of causes. But itās related, and also related to error design in general. If the crates Display were updated to not include the output from the wrapped io::Error, then it the display becomes much less useful when used without error-chain. For instance, if println!("{}", e) printed io error.
One thing Iād really appreciate is if this crate functioned, even in a degraded manner (i.e. no backtraces or std::error support) in no_std contexts, as it seems to becoming the de facto way to write Rust error boilerplate.
Perhaps this comment is looking a bit beyond the libs blitz, but it seems like an apropos time to bring it up.
I think error chain is very good (significantly better than the status quo before error chain), but I feel slightly concerned about how its trending toward becoming the de facto solution. I suspect error chain could be even better if the problem space were examined in a lang+libs framework, instead of just a libs framework (that is, considering potential extensions to the language as well).
For example, the existence of both links and foreign_links seems inelegant to me; is there a solution based on specialization that could combine them?
Even more abstractly, if error chain is going to become āthe wayto define an error in Rust,ā Iād like to see a more thorough discussion of what other options were considered and discarded, what the fundamental trade offs are, etc. Maybe that discussion exists and I just havenāt read it.
@withoutboats FWIW Iāve always considered error-chain to be something of hack and wish it didnāt have to exist, and I expect other solutions to appear. Both the existence of error-chain and its popularity in my mind speak to a weakness of the language and std. I hope though that even as error-chain is adopted it doesnāt prevent use of other error handling techniques, that it interoperates well.
It would be a fine result for me if error-chain got bumped to 1.0 basically as-is, with the understanding that error handling will continue to evolve, that there may be an error-chain 2.0, that other solutions might deprecate it completely.
Hey folks, Iām not sure if this is the right place and time, but maybe Iām lucky and you can help me out! If not, consider this a request for a ābest practicesā document that should be part of the error-chain docs!
Iām currently evaluating switching Diesel to use error-chain internally. One of our main concerns is presenting an interface to the user of the query builder that is forward-compatible, i.e., one we can add new errors to without breaking user code, while at the same time give return nice error that are easy to debug. My current idea is using error-chain (because itās pretty nice to use; weād probably have one root error type, plus maybe more specific error types in modules) and only exposing a struct DieselError { inner: LeRootErrorChainError } to the user. Iāve written a bit more here.
From what Iāve seen of error-chain so far, it seem geared toward application developers, not library authors. Would you recommend us using it at all? Is there anything we should definitely keep in mind?
It also seems a bit unfortunate to have an almost identical public copy of quick_error in the crate. If someone uses both quick_error and error_chain, the order the crates are imported will determine what version of the quick_error macro gets used:
Thanks, folks, for advancing this while I was away on vacation last week!
Today I did a careful review of the crate myself, and added a bunch of discussion items, including pulling the most important guidelines issues into scope. You can see these at the top, but for reference:
There are several issues around the macro syntax:
The syntax not matching corresponding declaration form
The types declaration, with its hand-rolled system of defaults, doesnāt quite feel ārusticā
I definitely agree, and I think such a discussion would ideally be part of the crate evaluation. I have similar reservations to yours about the links/foreign links split and its rationale, for example.
I'm not sure we'll be able to complete a deep dive into the tradeoffs during the official libs team meeting, but I think it's something we can and should do out of band. Even if we don't end up changing the library much for a 1.0, it'd be great to document the design rationale and note shortcomings that might be addressed with new language features.