chore: make sure error stack includes message as before #31691 (#31934)

This brings stack formatting to how it was prior to
1686e5174d
so that the ports can use it.
This commit is contained in:
Yury Semikhatsky 2024-07-31 10:58:37 -07:00 committed by GitHub
parent 7c55b94280
commit edb89dcb66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -170,8 +170,16 @@ export function source() {
if (typeof value === 'bigint')
return { bi: value.toString() };
if (isError(value))
return { e: { n: value.name, m: value.message, s: value.stack || '' } };
if (isError(value)) {
let stack;
if (value.stack?.startsWith(value.name + ': ' + value.message)) {
// v8
stack = value.stack;
} else {
stack = `${value.name}: ${value.message}\n${value.stack}`;
}
return { e: { n: value.name, m: value.message, s: stack } };
}
if (isDate(value))
return { d: value.toJSON() };
if (isURL(value))