-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Bury Error::description() #2230
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
- Feature Name: optional_error_description | ||
- Start Date: 2017-11-29 | ||
- RFC PR: (leave this empty) | ||
- Rust Issue: (leave this empty) | ||
|
||
# Default implementation of `Error::description()` | ||
[summary]: #summary | ||
|
||
Provide a default implementation of the `Error` trait's `description()` method to save users trouble of implementing this flawed method. | ||
|
||
# Motivation | ||
[motivation]: #motivation | ||
|
||
The `description()` method is a waste of time for implementors and users of the `Error` trait. There's high overlap between description and `Display`, which creates redundant implementation work and confusion about relationship of these two ways of displaying the error. | ||
|
||
The `description()` method can't easily return a formatted string with per-instance error description. That's a gotcha for novice users struggling with the borrow checker, and gotcha for users trying to display the error, because the `description()` is going to return a less informative message than the `Display` trait. | ||
|
||
# Guide-level explanation | ||
[guide-level-explanation]: #guide-level-explanation | ||
|
||
Let's steer users away from the `description()` method. | ||
|
||
1. Change the `description()` documentation to suggest use of the `Display` trait instead. | ||
2. Provide a default implementation of the `description()` so that the `Error` trait can be implemented without worrying about this method. | ||
|
||
# Reference-level explanation | ||
[reference-level-explanation]: #reference-level-explanation | ||
|
||
The description method can have default implementation returning `core::intrinsics::type_name::<Self>()`. This preserves basic functionality of this method for backwards compatibility. | ||
|
||
Users of the `Error` trait can then pretend this method does not exist. | ||
|
||
# Drawbacks | ||
[drawbacks]: #drawbacks | ||
|
||
When users start omitting bespoke `description()` implementations, code that still uses this method will get machine-generated rather than human-written descriptions, so success of this change depends also on steering authors away from using this method as well. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not also formally deprecate the method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to see the method formally deprecated at some point, but I agree that we should give it several releases before doing so, and make sure it has minimal impact on the ecosystem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for eventual formal deprecation |
||
|
||
# Rationale and alternatives | ||
[alternatives]: #alternatives | ||
|
||
- Do nothing, and rely on 3rd party crates to improve usability of errors (e.g. various crates providing `Error`-implementing macros or the `Fail` trait). | ||
- The default message returned by `description` could be different. | ||
- it could be even less useful to discourage use of this method harder, e.g. just `"error"`, | ||
- it could try to be nicer, e.g. use the type's doccomment as the description, or convert type name to a sentence (`FileNotFoundError` -> "error: file not found"). | ||
|
||
# Unresolved questions | ||
[unresolved]: #unresolved-questions | ||
|
||
None yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we comfortable somewhat stabilizing
type_name
? This makes it at least somewhat easy to (abuse) this to get it's functionality on stable for non-error types in at least binaries where the impl of Error doesn't matter too much from an exposed API perspective.Either way, we should explicitly state that this method's default return value is not stable and should not be relied on from version to version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simon's current PR just returns
""