endo icon indicating copy to clipboard operation
endo copied to clipboard

v8 error taming should leverage `prepareStackTrace`

Open mhofman opened this issue 2 years ago • 4 comments

What is the Problem Being Solved?

Error.prepareStackTrace can be used by Node.js to apply source maps to the captured stack trace. However SES sets its own prepareStackTrace during v8 Error taming. Instead of completely discarding it. Maybe instead it should leverage as much as possible the existing prepareStackTrace to prepare its own stack strings?

Furthermore, if the start compartment set a prepareStackTrace after lockdown, it seems the returned value will be used for the .stack property instead of the empty string, even if errorTaming is set to 'safe': https://github.com/endojs/endo/blob/2a85f8aa6684b4d4a92fea48ccc63d01ccddc85e/packages/ses/src/error/tame-v8-error-constructor.js#L301-L304

Description of the Design

Use the original prepareStackTrace to generate the stack string.

Alternatively implement source map support in endo itself (maybe once part of the error handling logic has been ejected from SES as a trusted shim?, see #945). While node's prepareStackTrace implementation is not very modular, it should be possible to rebuild it on top of findSourceMap.

Security Considerations

None particularly. The start compartment is already in position to decide how lockdown should tame errors, and can also set prepareStackTrace after lockdown

Scaling Considerations

None

Test Plan

load some minified source which throws errors in Node.js with --use-source-maps and verify stack traces are mapped.

Upgrade Considerations

None particular

mhofman avatar Sep 30 '23 01:09 mhofman

Hi @mhofman , I've co-assigned myself to this.

erights avatar Jul 12 '24 22:07 erights

Use the original prepareStackTrace to generate the stack string.

I believe I explored this, and that didn't work

mhofman avatar Jul 12 '24 23:07 mhofman

It looks like since I filed this issue, Node.js actually decided to expose their internal prepareStackTrace, which should make this very straightforward.

mhofman avatar Sep 15 '25 23:09 mhofman

Huh. Testing just now, it was added sometime between Node v18.19.0 exclusive and Node v20.18.3 inclusive.

erights avatar Sep 16 '25 00:09 erights