cherry-pick(#31934): chore: make sure error stack includes message as… (#31935)

… before #31691

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 11:07:45 -07:00 committed by GitHub
parent dfecfa5be1
commit ca9ddff7ca
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))