Skip to content

Commit 2ed7ae3

Browse files
committed
Add EncodingError::external
1 parent f3ec0fb commit 2ed7ae3

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/error.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pub enum EncodingErrorKind {
1010
Overflow,
1111
/// Buffer contained invalid data during decoding.
1212
InvalidData,
13+
/// Some external error occurred causing a [`CompactEncoding`] method to fail.
14+
External,
1315
}
1416

1517
/// Encoding/decoding error.
@@ -56,6 +58,13 @@ impl EncodingError {
5658
message: message.to_string(),
5759
}
5860
}
61+
/// Helper function for making an invalid data error
62+
pub fn external(message: &str) -> Self {
63+
Self {
64+
kind: EncodingErrorKind::External,
65+
message: message.to_string(),
66+
}
67+
}
5968
}
6069

6170
impl fmt::Display for EncodingError {
@@ -64,8 +73,11 @@ impl fmt::Display for EncodingError {
6473
EncodingErrorKind::OutOfBounds => "Compact encoding failed, out of bounds",
6574
EncodingErrorKind::Overflow => "Compact encoding failed, overflow",
6675
EncodingErrorKind::InvalidData => "Compact encoding failed, invalid data",
76+
EncodingErrorKind::External => {
77+
"An external error caused a compact encoding operation to fail"
78+
}
6779
};
68-
write!(f, "{}: {}", prefix, self.message)
80+
write!(f, "{}: {}", prefix, self.message,)
6981
}
7082
}
7183

0 commit comments

Comments
 (0)