next.js
d8bfc3c9 - Don't parse error message lines as stack frames in the server error inspector (#99888)

Commit
54 days ago
Don't parse error message lines as stack frames in the server error inspector (#99888) ## What Fix formatting of `Errors` containing multiline `message` properties Multi-line error messages printed in the terminal could end with bogus stack frames such as: ``` at <unknown> (Turbopack is configured to run webpack loaders and PostCSS transforms in ...) at <unknown> (https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopackPluginRuntimeStrategy) ``` `parseAndSourceMap` in `patch-error-inspect.ts` passed the whole of `error.stack` to the stack parser, and `error.stack` starts with the message. `stacktrace-parser`'s Gecko pattern accepts any line that *starts with* a scheme-like word (`http`, `file`, `webpack`, `turbopack`, `about`, `rsc`, ...), case-insensitively and without requiring a colon. So message lines such as a docs URL, or prose that happens to start with "Turbopack", were treated as frames. The fix is to only pass the 'stack frame' part of th parses the part of the stack after the message: - `prepareUnsourcemappedStackTrace`, which formats every stack, records the offset of the first frame on the error under a non-enumerable `Symbol.for` key, together with the string it produced. If `error.stack` is still that string, the frames are found exactly, even if the message or name changed afterwards. - For stacks we didn't format, or that were replaced afterwards, it strips the `name: message` header if `error.stack` starts with it, and otherwise parses the whole stack as before. <!-- NEXT_JS_LLM -->
Author
Parents
Loading