-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give accessors to wasmtime::Trap
causes
#3033
Conversation
Subscribe to Label Actioncc @peterhuene
This issue or pull request has been labeled: "wasmtime:api"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
Could you describe a bit more the use case for getting the user-generated error message? Is the main goal to print the error without printing the backtrace? Otherwise for implementing |
Yes, this is exactly my goal. Actually in our embedding the backtrace is post-processed for display, mainly for function names demangling, but now I'm seeing that Wasmtime does that for us. Our display tries to be minimal and display a bit less information, though. So getting the user-generated error message allows us to customize the error message that we display.
It seems that |
One option to fix this is to simply remove the backtrace printing from Another possibility to do this would be to implement something like For printing twice, it's not actually I do think it's fine to implement |
We've discussed this a bit, and turns out that displaying the error reason is sufficient for my use case, while remaining abstract enough. Thanks Alex for the suggestions! |
After some thinking and discussion, another reasonable path would be to invert the default:
This would be a (small) breaking change, and I'm not sure how people are using it, so I'm tempted to just keep the same default as it is right now, but could be convinced otherwise. |
Indeed I agree that's a possibility! (sorry meant to explain that before but it was brief) I think the best way to figure this out thought might be to follow the Rust community norms in this regard (since Rust error libraries can often carry backtraces as well). Looking at Would something like that be reasonable for y'all? It would be nice to somewhere have a Even if we go that route though I feel like we may still want this method so, even when backtraces are enabled, there's a specific way to print just the reason without the backtrace. |
This would work fine for our use case; curious to see other people's thoughts! |
Would you be up for sketching out what it would look like? Ideally we would actually avoid capturing a backtrace entirely on traps unless |
Hm actually on second thought after talking with some other folks I'm convinced that printing and capturing the backtrace by default is the right thing to do here. I think one thing we could do, though, is configure at a Would you be ok with merging this and we can figure out other details later as-needed? |
Yes, sounds good to me! |
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 fullDisplay
impl 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
Trap
implementedstd::error::Error
if 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. :)