Currently, NearExpect implementation for Result<T, E> discards the original error:
impl<T, E> NearExpect<T> for Result<T, E> {
fn near_expect(self, msg: impl AsRef<str>) -> T {
self.unwrap_or_else(|_| near_sdk::env::panic_str(msg.as_ref()))
}
}
The original error E is silently ignored, which makes debugging harder — the caller only sees the static message, not what actually went wrong.
Suggestion:
Add a bound E: core::fmt::Debug (or Display) and format the original error into the panic message:
impl<T, E: core::fmt::Debug> NearExpect<T> for Result<T, E> {
fn near_expect(self, msg: impl AsRef<str>) -> T {
self.unwrap_or_else(|err| {
near_sdk::env::panic_str(&format!("{}: {:?}", msg.as_ref(), err))
})
}
}
Trade-offs to consider:
- Adding E: Debug is a stricter bound — some Result types may not satisfy it (though in practice most errors implement Debug)
- Could keep the current impl as-is and add a separate method like near_expect_dbg to avoid breaking changes
Currently, NearExpect implementation for Result<T, E> discards the original error:
The original error E is silently ignored, which makes debugging harder — the caller only sees the static message, not what actually went wrong.
Suggestion:
Add a bound E: core::fmt::Debug (or Display) and format the original error into the panic message:
Trade-offs to consider: