Skip to content

Commit

Permalink
Implement std::error::Error for all error types that implement `Dis…
Browse files Browse the repository at this point in the history
…play` (#1089)
  • Loading branch information
kajacx authored Jun 25, 2024
1 parent 5ef1e8d commit aa007b4
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/core/src/untyped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,9 @@ impl UntypedError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for UntypedError {}

impl Display for UntypedError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/engine/executor/instrs/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ pub struct ResumableHostError {
caller_results: RegisterSpan,
}

#[cfg(feature = "std")]
impl std::error::Error for ResumableHostError {}

impl fmt::Display for ResumableHostError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.host_error.fmt(f)
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/engine/limits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub enum EnforcedLimitsError {
MinAvgBytesPerFunction { limit: u32, avg: u32 },
}

#[cfg(feature = "std")]
impl std::error::Error for EnforcedLimitsError {}

impl Display for EnforcedLimitsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/engine/limits/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub enum LimitsError {
InitialValueStackExceedsMaximum,
}

#[cfg(feature = "std")]
impl std::error::Error for LimitsError {}

impl Display for LimitsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/engine/translator/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ impl TranslationError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for TranslationError {}

impl Display for TranslationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/engine/translator/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ pub enum LabelError {
Unpinned { label: LabelRef },
}

#[cfg(feature = "std")]
impl std::error::Error for LabelError {}

impl Display for LabelError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/func/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub enum FuncError {
MismatchingResultLen,
}

#[cfg(feature = "std")]
impl std::error::Error for FuncError {}

impl Display for FuncError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ pub enum GlobalError {
},
}

#[cfg(feature = "std")]
impl std::error::Error for GlobalError {}

impl Display for GlobalError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/memory/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub enum MemoryError {
InvalidStaticBufferSize,
}

#[cfg(feature = "std")]
impl std::error::Error for MemoryError {}

impl Display for MemoryError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/module/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub enum ReadError {
UnknownError,
}

#[cfg(feature = "std")]
impl std::error::Error for ReadError {}

impl Display for ReadError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ pub enum FuelError {
OutOfFuel,
}

#[cfg(feature = "std")]
impl std::error::Error for FuelError {}

impl fmt::Display for FuelError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
3 changes: 3 additions & 0 deletions crates/wasmi/src/table/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum TableError {
TooManyTables,
}

#[cfg(feature = "std")]
impl std::error::Error for TableError {}

impl Display for TableError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down

0 comments on commit aa007b4

Please sign in to comment.