bnjbvr opened PR #3033 from trap-errors to main:
It wasn't possible to just retrieve a user-created error description in
wasmtime::Trap(i.e. created withwasmtime::Trap::new("hi there")). This user message would only show up as part of the fullDisplayimpl forTrap, which also prints out the unmangled backtrace and other information. A first commit adds auser_message()accessor to retrieve it, if it was set.As I was trying to find another way to get a custom error message, I saw that
Trapimplementedstd::error::Errorif the trap was created from anStdError. Unfortunately, it doesn't give access to it directly either, but it gives access to the underlyingsource()of the error itself. It would be nice to have access to the error itself, to not lose one layer of error information. As a result, I've tweakedsource()so it returns the error that was used to create the trap, and not the error's source directly. Conceptually it makes sense that the first source of the trap is the error that it was converted from, but it would also be reasonable to say that the trap is the error (so instead, we could just add another accessor to get the error). Discuss. :)
bnjbvr updated PR #3033 from trap-errors to main.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Could this return
impl Displayso if necessary we can change this in the future to returning something that isn't necessarily stored onSelf?
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Could this elaborate a bit on what the method does? For example I think this should explain how this is different from
Display for Trapand an example situation you might end up using this.
bnjbvr updated PR #3033 from trap-errors to main.
alexcrichton merged PR #3033.
Last updated: Dec 06 2025 at 06:05 UTC