-
Notifications
You must be signed in to change notification settings - Fork 14
Migration plan for Display vs source guidance #44
Description
In #27 we established that public API Error types need to be careful and consistent in how they expose information via the Error trait so as to avoid duplicating context when reporting errors. Later when preparing the blog post to first communicate this new guidance @BurntSushi noted that crates that need to change their error types based on the guidance will need a migration plan to mitigate issues caused by breaking runtime behavior of their error type's API. In this issue we're going to create a suggested migration plan for authors of libraries affected by this guidance, to ensure a smooth transition towards consistent error reporting across the Rust ecosystem.
Suggested Migration Plan
Note: We're interested in feedback in the guide and want to make it clear that this isn't an edict that The Library Team is passing down without any input from the rest of ecosystem. If these suggestions don't work for you please let us know.
Error types that go against this guidance need to be careful to avoid breaking runtime behavior of dependent crates. The biggest risk to be aware of is dependent crates who depend on calling downcast on the error returned from Error::source in order to react to specific source types. Additionally, dependent crates may be relying on the Error type printing itself and it's sources, so an upgrade might cause applications to give less detailed error messages to users. We recommend library authors who need to update their error types:
- Prefer removing source from the
Displayimpl, rather than removing it fromError::sourceand potentially breaking code that reacts to specific errors at runtime. - Treat changing the
Displayimpl as a breaking change and increment semver accordingly. - Document that the
Displaybehavior on your errors has changed, as visibly as you can, since your users may bump the version and assume it doesn't affect them if it compiles.