diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2020-08-30 18:43:31 +0200 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2020-08-30 18:43:31 +0200 |
commit | e9a89be939acf22cf17e3d6bc505a968a98d3dee (patch) | |
tree | 5a4ee8a514995133560e23650d5e908bbc75701a | |
parent | 4e36005680285a20ec50580f79ece8ec47f648e3 (diff) | |
download | nitrokey-rs-e9a89be939acf22cf17e3d6bc505a968a98d3dee.tar.gz nitrokey-rs-e9a89be939acf22cf17e3d6bc505a968a98d3dee.tar.bz2 |
Remove custom source implementation for Error
This patch removes the custom implementation of the source method of the
std::error::Error trait for the error::Error type. This means that the
default implementation is used that always returns None. The reason for
this change is that we already print the error message of the source
error in the Display implementation. This leads to a duplicated error
message if both Display and source are checked, for example with
anyhow’s error formatting.
See this thread for more information:
https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C6e0b4dc8-9059-a113-e98e-b49e52818c75%40posteo.net%3E
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | src/error.rs | 16 |
2 files changed, 5 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 736620d..e89fc44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Copyright (C) 2019-2020 Robin Krahl <robin.krahl@ireas.org> SPDX-License-Identifier: CC0-1.0 --> +# Unreleased +- Remove the custom `std::error::Error::source` implementation for + `error::Error` to avoid duplicate error messages. + # v0.7.0 (2020-07-14) - Refactor the `Error` enum so that it is `Send`, `Sync` and `'static`: - Remove the `sync::PoisonError` from the `PoisonError` variant. diff --git a/src/error.rs b/src/error.rs index 1aa1793..64a2ce0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -91,21 +91,7 @@ impl<'a, T: device::Device<'a>> From<(T, Error)> for Error { } } -impl error::Error for Error { - fn source(&self) -> Option<&(dyn error::Error + 'static)> { - match *self { - Error::CommandError(ref err) => Some(err), - Error::CommunicationError(ref err) => Some(err), - Error::ConcurrentAccessError => None, - Error::LibraryError(ref err) => Some(err), - Error::PoisonError => None, - Error::UnexpectedError(_) => None, - Error::UnknownError(_) => None, - Error::UnsupportedModelError => None, - Error::Utf8Error(ref err) => Some(err), - } - } -} +impl error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |