microsoft / node-api-dotnet

Advanced interoperability between .NET and JavaScript in the same process.
MIT License
426 stars 49 forks source link

Propagate .NET stack to JS for async errors #293

Closed jasongin closed 1 month ago

jasongin commented 1 month ago

When JS invokes/awaits an async .NET method, and the async .NET method throws an exception, the .NET stack trace was not propagated via the Error object thrown back to JS; only the error message was available. This fixes that by ensuring JSError captures the stack when constructed from the callbacks used when converting a .NET Task to JS Promise.

Unfortunately we don't get the JS part of the stack (as we do for sync errors); I could not find a way to do that for async errors. But the .NET part of the stack, where the error was actually thrown from, is likely to sufficient in most cases and is at least better than nothing.