Skip to content

Commit 9630182

Browse files
committed
Improve error handling in console logging and stringification
1 parent bcfb4a1 commit 9630182

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: scripts/common.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ webrtcperf.safeStringify = obj => {
55
const values = new Set()
66
try {
77
const ret = JSON.stringify(obj, (_, v) => {
8-
if (v instanceof Error) return v.message
8+
if (v instanceof Error) return `Error: ${v.message}`
99
if (typeof v !== 'object' || v === null || v === undefined) return v
1010
if (values.has(v)) return
1111
values.add(v)
@@ -24,10 +24,10 @@ webrtcperf.safeStringify = obj => {
2424
;['error', 'warn', 'info', 'log', 'debug'].forEach(method => {
2525
const nativeFn = console[method].bind(console)
2626
console[method] = function (...args) {
27-
const customArgs = args
27+
const msg = args
2828
.map(arg => {
2929
if (arg instanceof Error) {
30-
return arg.message
30+
return `Error: ${arg.message}`
3131
} else if (typeof arg === 'object') {
3232
return webrtcperf.safeStringify(arg)
3333
} else if (typeof arg === 'string') {
@@ -41,7 +41,7 @@ webrtcperf.safeStringify = obj => {
4141
.filter(arg => arg.length > 0)
4242
.join(' ')
4343
if (window.serializedConsoleLog) {
44-
void window.serializedConsoleLog(method, customArgs)
44+
void window.serializedConsoleLog(method, msg)
4545
}
4646

4747
return nativeFn(...args)

0 commit comments

Comments
 (0)