github-actions[bot] commented on issue #3033:
Subscribe to Label Action
cc @peterhuene
<details>
This issue or pull request has been labeled: "wasmtime:api"Thus the following users have been cc'd because of the following labels:
- peterhuene: wasmtime:api
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
alexcrichton commented on issue #3033:
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
source
the main thing to account for is that we want to make sure that error messages aren't double-printed. We print out a full chain of errors and if an error is returned fromsource
then it shouldn't be printed byDisplay for Trap
because that would otherwise mean the trap error message would get printed twice.
bnjbvr commented on issue #3033:
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?
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 shouldn't be printed by Display for Trap
It seems that
Display
forTrap
doesn't iterate on an error sequence, but only shows theTrapReason
and the backtrace generated from the frames. Am I missing something? In any case, I'm happy to provide an alternativeerror()
accessor that returns the plain error (and keep thesource()
implementation as it was before this PR), or just to remove this last commit (if we can agree on getting the user message accessor).
alexcrichton commented on issue #3033:
One option to fix this is to simply remove the backtrace printing from
Trap
, but personally I feel like it's the right default (I could be convinced otherwise though).Another possibility to do this would be to implement something like
fn display(&self) -> impl fmt::Display
which returns basically whatDisplay
does minus the backtrace.For printing twice, it's not actually
Display for Trap
that prints the error twice. ADisplay
implementation for an error should print the message for just that error, and higher level libraries which generate reports, such asanyhow::Error
, will do the iteration. I think that if you print outanyhow::Error
where there's a trap inside (printed using{:?}
which isanyhow
's way of printing the full error backtrace) then you'll see the error printed twice.I do think it's fine to implement
source
, though, it just involves not printing the error itself when we're of that variant. Instead a placeholder like "user-generated error" would be printed instead.
bnjbvr commented on issue #3033:
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!
bnjbvr commented on issue #3033:
After some thinking and discussion, another reasonable path would be to invert the default:
- have
Display
only print the oneliner reason,- and have
display_with_backtrace
return animpl Display
that showed the reason and the backtraceThis 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.
alexcrichton commented on issue #3033:
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
anyhow
it looks like explicit opt-in is required to enable backtraces (via env vars). This means that backtraces wouldn't be captured by default, but you could opt-in on a per-execution basis to doing so.Would something like that be reasonable for y'all? It would be nice to somewhere have a
note: use WASMTIME_BACKTRACE=1 to get a backtrace
, but I'm not sure ifimpl Display for Trap
is the best location to put that. I'm not sure where it would go...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.
bnjbvr commented on issue #3033:
This would work fine for our use case; curious to see other people's thoughts!
alexcrichton commented on issue #3033:
Would you be up for sketching out what it would look like? Ideally we would actually avoid capturing a backtrace entirely on traps unless
WASMTIME_BACKTRACE=1
I think?
alexcrichton commented on issue #3033:
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
Store
level whether backtraces are captured or not, but otherwise I think we'd want something like this method to print the reason of the trap.Would you be ok with merging this and we can figure out other details later as-needed?
bnjbvr commented on issue #3033:
Yes, sounds good to me!
Last updated: Nov 22 2024 at 16:03 UTC