Skip to content

Commit

Permalink
test: Guard against unprintable console.log arguments
Browse files Browse the repository at this point in the history
Let's never abort a test just because converting a console.log
argument crashes.
  • Loading branch information
mvollmer committed Nov 8, 2023
1 parent cbc151c commit 87c798b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions test/common/chromium-cdp-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,20 @@ function clearExceptions() {
}

function stringifyConsoleArg(arg) {
if (arg.type === 'string')
return arg.value;
if (arg.type === 'object') {
const obj = {};
arg.preview.properties.forEach(prop => {
obj[prop.name] = prop.value.toString();
});
return JSON.stringify(obj);
try {
if (arg.type === 'string')
return arg.value;
if (arg.type === 'object') {
const obj = {};
arg.preview.properties.forEach(prop => {
obj[prop.name] = prop.value.toString();
});
return JSON.stringify(obj);
}
return JSON.stringify(arg);
} catch {
return "???";
}
return JSON.stringify(arg);
}

function setupLogging(client) {
Expand Down

0 comments on commit 87c798b

Please sign in to comment.