Skip to content

Commit 1a26274

Browse files
committed
Update changelog and docs for #60
1 parent df8f93a commit 1a26274

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
# fs-err Changelog
22

3-
* Change errors to output original `std::io::Error` information Display by default. This functionality can be disabled for [anyhow](https://docs.rs/anyhow/latest/anyhow/) users by using the new feature `expose_original_error` ([#60](https://github.com/andrewhickman/fs-err/pull/60)).
3+
## 3.0.0
4+
5+
* Error messages now include the original message from `std::io::Error` by default ([#60](https://github.com/andrewhickman/fs-err/pull/60)). Previously this was exposed through the [`Error::source()`](https://doc.rust-lang.org/stable/std/error/trait.Error.html#method.source) method. For example, previously a message would look like:
6+
7+
```
8+
failed to open file `file.txt`
9+
```
10+
11+
and you would have to remember to print the source, or use a library like `anyhow` to print the full chain of source errors. The new error message includes the cause by default
12+
13+
```
14+
failed to open file `file.txt`: The system cannot find the file specified. (os error 2)
15+
```
16+
17+
Note that the original error is no longer exposed though [`Error::source()`](https://doc.rust-lang.org/stable/std/error/trait.Error.html#method.source) by default. If you need access to it, you can restore the previous behaviour with the `expose_original_error` feature flag.
418

519
## 2.11.0
620

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ The system cannot find the file specified. (os error 2)
3030
...but if we use fs-err instead, our error contains more actionable information:
3131

3232
```txt
33-
failed to open file `does not exist.txt`
34-
caused by: The system cannot find the file specified. (os error 2)
33+
failed to open file `does not exist.txt`: The system cannot find the file specified. (os error 2)
3534
```
3635

3736
## Usage
@@ -66,10 +65,11 @@ println!("Program config: {:?}", decoded);
6665

6766
```
6867

69-
[std::fs]: https://doc.rust-lang.org/stable/std/fs/
70-
[std::io::Error]: https://doc.rust-lang.org/stable/std/io/struct.Error.html
71-
[std::io::Read]: https://doc.rust-lang.org/stable/std/io/trait.Read.html
72-
[serde_json]: https://crates.io/crates/serde_json
68+
## Feature flags
69+
70+
* `expose_original_error`: when enabled, the [`Error::source()`](https://doc.rust-lang.org/stable/std/error/trait.Error.html#method.source) method of errors returned by this crate return the original `io::Error`. To avoid duplication in error messages,
71+
this also suppresses printing its message in their `Display` implementation, so make sure that you are printing the full error chain.
72+
7373

7474
## Minimum Supported Rust Version
7575

@@ -79,6 +79,11 @@ This crate will generally be conservative with rust version updates. It uses the
7979

8080
If the `tokio` feature is enabled, this crate will inherit the MSRV of the selected [`tokio`](https://crates.io/crates/tokio) version.
8181

82+
[std::fs]: https://doc.rust-lang.org/stable/std/fs/
83+
[std::io::Error]: https://doc.rust-lang.org/stable/std/io/struct.Error.html
84+
[std::io::Read]: https://doc.rust-lang.org/stable/std/io/trait.Read.html
85+
[serde_json]: https://crates.io/crates/serde_json
86+
8287
## License
8388

8489
Licensed under either of

src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl fmt::Display for Error {
103103

104104
// The `expose_original_error` feature indicates the caller should display the original error
105105
#[cfg(not(feature = "expose_original_error"))]
106-
write!(formatter, " caused by: {}", self.source)?;
106+
write!(formatter, ": {}", self.source)?;
107107

108108
Ok(())
109109
}
@@ -204,7 +204,7 @@ impl fmt::Display for SourceDestError {
204204

205205
// The `expose_original_error` feature indicates the caller should display the original error
206206
#[cfg(not(feature = "expose_original_error"))]
207-
write!(formatter, " caused by: {}", self.source)?;
207+
write!(formatter, ": {}", self.source)?;
208208

209209
Ok(())
210210
}

src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ The system cannot find the file specified. (os error 2)
2222
...but if we use fs-err instead, our error contains more actionable information:
2323
2424
```txt
25-
failed to open file `does not exist.txt`
26-
caused by: The system cannot find the file specified. (os error 2)
25+
failed to open file `does not exist.txt`: The system cannot find the file specified. (os error 2)
2726
```
2827
29-
> Note: Users of `anyhow` or other libraries that format an Error's sources can enable the `expose_original_error` feature to control the formatting of the orginal error message.
30-
> When enabled, the `std::fmt::Display` implementation will emit the failed operation and paths but not the original `std::io::Error`. It will instead provide access via [Error::source](https://doc.rust-lang.org/std/error/trait.Error.html#method.source), which will be used by `anyhow` (or similar) libraries.
31-
3228
# Usage
3329
3430
fs-err's API is the same as [`std::fs`][std::fs], so migrating code to use it is easy.
@@ -63,6 +59,20 @@ println!("Program config: {:?}", decoded);
6359
# Ok::<(), Box<dyn std::error::Error>>(())
6460
```
6561
62+
# Feature flags
63+
64+
* `expose_original_error`: when enabled, the [`Error::source()`](https://doc.rust-lang.org/stable/std/error/trait.Error.html#method.source) method of errors returned by this crate return the original `io::Error`. To avoid duplication in error messages,
65+
this also suppresses printing its message in their `Display` implementation, so make sure that you are printing the full error chain.
66+
67+
68+
# Minimum Supported Rust Version
69+
70+
The oldest rust version this crate is tested on is **1.40**.
71+
72+
This crate will generally be conservative with rust version updates. It uses the [`autocfg`](https://crates.io/crates/autocfg) crate to allow wrapping new APIs without incrementing the MSRV.
73+
74+
If the `tokio` feature is enabled, this crate will inherit the MSRV of the selected [`tokio`](https://crates.io/crates/tokio) version.
75+
6676
[std::fs]: https://doc.rust-lang.org/stable/std/fs/
6777
[std::io::Error]: https://doc.rust-lang.org/stable/std/io/struct.Error.html
6878
[std::io::Read]: https://doc.rust-lang.org/stable/std/io/trait.Read.html

0 commit comments

Comments
 (0)