Skip to content

Commit 761643f

Browse files
authored
Merge pull request #863 from r00ster91/patch-2
Fix some "it's"
2 parents 5bdd9d2 + 6196d79 commit 761643f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

posts/inside-rust/2021-07-01-What-the-error-handling-project-group-is-working-towards.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ thread 'main' panicked at 'config is always valid and exists: Error(SourceError)
8585
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
8686
```
8787

88-
Now, I definitely don't think this is what we want as a default when promoting recoverable errors to non-recoverable errors! `unwrap` and `expect` work by stringifying the error variant using it's `Debug` impl, but this is often the wrong operation for types that implement the `Error` trait. By converting the `Error` to a `String` we lose access to the pieces of context we carefully split up via the `Error` trait, and in all likelihood the `derive(Debug)` output of our error types won't even include the error messages in our `Display` impls.
88+
Now, I definitely don't think this is what we want as a default when promoting recoverable errors to non-recoverable errors! `unwrap` and `expect` work by stringifying the error variant using its `Debug` impl, but this is often the wrong operation for types that implement the `Error` trait. By converting the `Error` to a `String` we lose access to the pieces of context we carefully split up via the `Error` trait, and in all likelihood the `derive(Debug)` output of our error types won't even include the error messages in our `Display` impls.
8989

9090
Rust's panic infrastructure doesn't provide a method for converting an `Error` type into a panic, it only supports converting `Debug` types into panics, and we feel that this is a major issue. Similarly, there's no convenient tools provided by the language for printing an error and all of its source's error messages.
9191

@@ -155,7 +155,7 @@ println!("Error: {}", Report::from(error));
155155
// Error: outermost error: second error: root error
156156
```
157157

158-
Or multiple lines with each error message on it's own line :
158+
Or multiple lines with each error message on its own line :
159159

160160

161161
```rust
@@ -222,7 +222,7 @@ So how do we avoid this? We adopt a consistent separation for `Display` and `sou
222222

223223
To resolve this issue, project error handling recently created a guideline for [how to implement `Display::fmt` and `Error::source`](https://github.com/rust-lang/project-error-handling/issues/27#issuecomment-763950178). In it we make the following recommendation:
224224

225-
**An error type with a source error should either return that error via `source` or include that source's error message in it's own `Display` output, but never both.**
225+
**An error type with a source error should either return that error via `source` or include that source's error message in its own `Display` output, but never both.**
226226

227227
We figure the default will be to return errors via source. That way source errors can be reacted to via `downcast` when appropriate. This is particularly important for libraries that are changing existing public error types. For these libraries removing an error from `source` is a breaking change that isn't detected at compile time, making a major version bump likely insufficient. Changing the `Display` output is also a breaking change, though a less dangerous one. To help with this we've drafted a suggested migration plan: [rust-lang/project-error-handling#44](https://github.com/rust-lang/project-error-handling/issues/44).
228228

0 commit comments

Comments
 (0)