Make sure formatter errors are emitted by the default Write::write_fmt
Previously, if an error was returned from the formatter that did not originate in an underlying writer error, Write::write_fmt would return successfully even if the formatting did not complete (was interrupted by an `fmt::Error` return). Now we choose to emit an io::Error with kind Other for formatter errors. Since this may reveal error returns from `write!()` and similar that previously passed silently, it's a kind of a [breaking-change].
This commit is contained in:
parent
8842e28be8
commit
6cfafad3c5
2 changed files with 62 additions and 1 deletions
|
@ -1055,7 +1055,14 @@ pub trait Write {
|
|||
let mut output = Adaptor { inner: self, error: Ok(()) };
|
||||
match fmt::write(&mut output, fmt) {
|
||||
Ok(()) => Ok(()),
|
||||
Err(..) => output.error
|
||||
Err(..) => {
|
||||
// check if the error came from the underlying `Write` or not
|
||||
if output.error.is_err() {
|
||||
output.error
|
||||
} else {
|
||||
Err(Error::new(ErrorKind::Other, "formatter error"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue