core: add debug-error feature to have a proper debug implementation of errors

This commit is contained in:
Sosthène Guédon
2025-05-14 10:16:21 +02:00
committed by sosthene-nitrokey
parent 4f86dc4f8f
commit 6653300ce3
2 changed files with 25 additions and 1 deletions
+1
View File
@@ -22,3 +22,4 @@ heapless-bytes04 = ["dep:heapless-bytes04"]
heapless07 = ["dep:heapless07"]
heapless08 = ["dep:heapless08"]
serde = ["dep:serde"]
debug-error = []
+24 -1
View File
@@ -202,7 +202,30 @@ impl Error {
/// As a short-term fix, the `Debug` implementation currently always returns a static string.
impl Debug for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Error").finish()
#[cfg(not(feature = "debug-error"))]
{
f.debug_struct("Error").finish()
}
#[cfg(feature = "debug-error")]
{
match self {
&Self::IO => f.write_str("IO"),
&Self::CORRUPTION => f.write_str("CORRUPTION"),
&Self::NO_SUCH_ENTRY => f.write_str("NO_SUCH_ENTRY"),
&Self::ENTRY_ALREADY_EXISTED => f.write_str("ENTRY_ALREADY_EXISTED"),
&Self::PATH_NOT_DIR => f.write_str("PATH_NOT_DIR"),
&Self::PATH_IS_DIR => f.write_str("PATH_IS_DIR"),
&Self::DIR_NOT_EMPTY => f.write_str("DIR_NOT_EMPTY"),
&Self::BAD_FILE_DESCRIPTOR => f.write_str("BAD_FILE_DESCRIPTOR"),
&Self::FILE_TOO_BIG => f.write_str("FILE_TOO_BIG"),
&Self::INVALID => f.write_str("INVALID"),
&Self::NO_SPACE => f.write_str("NO_SPACE"),
&Self::NO_MEMORY => f.write_str("NO_MEMORY"),
&Self::NO_ATTRIBUTE => f.write_str("NO_ATTRIBUTE"),
&Self::FILENAME_TOO_LONG => f.write_str("FILENAME_TOO_LONG"),
other => f.debug_tuple("Error").field(&other.code).finish(),
}
}
}
}