From f2280a5932093ceef69f93fc247ba6c505b35478 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:02:46 +0100 Subject: [PATCH] feat(sol-types): improve ABI decoding error messages (#851) --- crates/sol-types/src/errors.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/sol-types/src/errors.rs b/crates/sol-types/src/errors.rs index 8f3c7a9ee..4356c515f 100644 --- a/crates/sol-types/src/errors.rs +++ b/crates/sol-types/src/errors.rs @@ -90,13 +90,22 @@ impl fmt::Display for Error { Self::TypeCheckFail { expected_type, data } => { write!(f, "type check failed for {expected_type:?} with data: {data}",) } - Self::Overrun => f.write_str("buffer overrun while deserializing"), - Self::Reserve(e) => e.fmt(f), - Self::BufferNotEmpty => f.write_str("buffer not empty after deserialization"), - Self::ReserMismatch => f.write_str("reserialization did not match original"), - Self::RecursionLimitExceeded(limit) => { - write!(f, "recursion limit of {limit} exceeded during decoding") + Self::Overrun + | Self::BufferNotEmpty + | Self::ReserMismatch + | Self::RecursionLimitExceeded(_) => { + f.write_str("ABI decoding failed: ")?; + match *self { + Self::Overrun => f.write_str("buffer overrun while deserializing"), + Self::BufferNotEmpty => f.write_str("buffer not empty after deserialization"), + Self::ReserMismatch => f.write_str("reserialization did not match original"), + Self::RecursionLimitExceeded(limit) => { + write!(f, "recursion limit of {limit} exceeded during decoding") + } + _ => unreachable!(), + } } + Self::Reserve(e) => e.fmt(f), Self::InvalidEnumValue { name, value, max } => { write!(f, "`{value}` is not a valid {name} enum value (max: `{max}`)") }