Skip to content

Commit a281425

Browse files
author
Robert Jackson
committed
Ensure logging of modules that failed to gather telemetry.
Calling `console.error` from within the `page.evaluate` callback logs the error to puppeteer instances console not the console that is actually running the codemod process. This fixes that issue (so the messages actually bubble up now) by using `page.exposeFunction` which **does** have access to the current node process.
1 parent 94a469a commit a281425

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lib/gather-telemetry.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ module.exports = async function gatherTelemetry(url) {
77

88
await page.goto(url);
99

10+
await page.exposeFunction("logErrorInNodeProcess", message => {
11+
console.error(message); // eslint-disable-line no-console
12+
});
13+
1014
// Get the "viewport" of the page, as reported by the page.
1115
const telemetry = await page.evaluate(() => {
1216
const SKIPPED_MODULES = ["fetch/ajax"];
@@ -31,7 +35,9 @@ module.exports = async function gatherTelemetry(url) {
3135
}
3236
} catch (error) {
3337
// log the error, but continue
34-
console.error(`error evaluating \`${modulePath}\`: ${error.message}`); // eslint-disable-line no-console
38+
window.logErrorInNodeProcess(
39+
`error evaluating \`${modulePath}\`: ${error.message}`
40+
);
3541
}
3642
}
3743

0 commit comments

Comments
 (0)