Skip to content

Commit

Permalink
fix: fixed structuredClone bug with try/catch for now
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Dec 18, 2024
1 parent 60f7257 commit d7d7b30
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions helpers/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,24 +282,34 @@ for (const level of logger.config.levels) {
// clone the data so that we don't mutate it
// <https://nodejs.org/api/globals.html#structuredclonevalue-options>
// <https://github.com/ungap/structured-clone>
message = global.structuredClone(message, {
// avoid throwing
lossy: true,
// avoid throwing *and* looks for toJSON
json: true
});
try {
message = global.structuredClone(message, {
// avoid throwing
lossy: true,
// avoid throwing *and* looks for toJSON
json: true
});
} catch (err) {
console.error({ message, err });
message = JSON.parse(safeStringify(message));
}
}

if (typeof meta === 'object' && global.structuredClone) {
// clone the data so that we don't mutate it
// <https://nodejs.org/api/globals.html#structuredclonevalue-options>
// <https://github.com/ungap/structured-clone>
meta = global.structuredClone(meta, {
// avoid throwing
lossy: true,
// avoid throwing *and* looks for toJSON
json: true
});
try {
meta = global.structuredClone(meta, {
// avoid throwing
lossy: true,
// avoid throwing *and* looks for toJSON
json: true
});
} catch (err) {
console.error({ meta, err });
message = JSON.parse(safeStringify(message));
}
}

// add `isCodeBug` parsing here to `err` (safeguard)
Expand Down

0 comments on commit d7d7b30

Please sign in to comment.