Skip to content

Commit f2fc946

Browse files
core: add debug-error feature to have a proper debug implementation of errors
1 parent 3d33ff5 commit f2fc946

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ heapless-bytes04 = ["dep:heapless-bytes04"]
2222
heapless07 = ["dep:heapless07"]
2323
heapless08 = ["dep:heapless08"]
2424
serde = ["dep:serde"]
25+
debug-error = []

core/src/io.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,30 @@ impl Error {
202202
/// As a short-term fix, the `Debug` implementation currently always returns a static string.
203203
impl Debug for Error {
204204
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
205-
f.debug_struct("Error").finish()
205+
#[cfg(not(feature = "debug-error"))]
206+
{
207+
f.debug_struct("Error").finish()
208+
}
209+
#[cfg(feature = "debug-error")]
210+
{
211+
match self {
212+
&Self::IO => f.write_str("IO"),
213+
&Self::CORRUPTION => f.write_str("CORRUPTION"),
214+
&Self::NO_SUCH_ENTRY => f.write_str("NO_SUCH_ENTRY"),
215+
&Self::ENTRY_ALREADY_EXISTED => f.write_str("ENTRY_ALREADY_EXISTED"),
216+
&Self::PATH_NOT_DIR => f.write_str("PATH_NOT_DIR"),
217+
&Self::PATH_IS_DIR => f.write_str("PATH_IS_DIR"),
218+
&Self::DIR_NOT_EMPTY => f.write_str("DIR_NOT_EMPTY"),
219+
&Self::BAD_FILE_DESCRIPTOR => f.write_str("BAD_FILE_DESCRIPTOR"),
220+
&Self::FILE_TOO_BIG => f.write_str("FILE_TOO_BIG"),
221+
&Self::INVALID => f.write_str("INVALID"),
222+
&Self::NO_SPACE => f.write_str("NO_SPACE"),
223+
&Self::NO_MEMORY => f.write_str("NO_MEMORY"),
224+
&Self::NO_ATTRIBUTE => f.write_str("NO_ATTRIBUTE"),
225+
&Self::FILENAME_TOO_LONG => f.write_str("FILENAME_TOO_LONG"),
226+
other => f.debug_tuple("Error").field(&other.code).finish(),
227+
}
228+
}
206229
}
207230
}
208231

0 commit comments

Comments
 (0)