Skip to content

Commit

Permalink
Merge pull request stereobooster#200 from stereobooster/fail-on-unhan…
Browse files Browse the repository at this point in the history
…dled-promise

Fail on unhandled promise rejection
  • Loading branch information
stereobooster authored Jun 19, 2018
2 parents 695f794 + fc6808f commit 8924f23
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/puppeteer_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,23 @@ const enableLogging = opt => {
mapStackTrace(e.stack || e.message, {
isChromeOrEdge: true,
store: sourcemapStore || {}
}).then(result => {
// TODO: refactor mapStackTrace: return array not a string, return first row too
const stackRows = result.split("\n");
const puppeteerLine =
stackRows.findIndex(x => x.includes("puppeteer")) ||
stackRows.length - 1;

console.log(
`🔥 ${route} pageerror: ${(e.stack || e.message).split("\n")[0] +
"\n"}${stackRows.slice(0, puppeteerLine).join("\n")}`
);
}).catch((e2) => {
console.log(`🔥 ${route} pageerror:`, e);
console.log(`️️️⚠️ ${route} error in Source Maps:`, e2.message);
});
})
.then(result => {
// TODO: refactor mapStackTrace: return array not a string, return first row too
const stackRows = result.split("\n");
const puppeteerLine =
stackRows.findIndex(x => x.includes("puppeteer")) ||
stackRows.length - 1;

console.log(
`🔥 ${route} pageerror: ${(e.stack || e.message).split("\n")[0] +
"\n"}${stackRows.slice(0, puppeteerLine).join("\n")}`
);
})
.catch(e2 => {
console.log(`🔥 ${route} pageerror:`, e);
console.log(`️️️⚠️ ${route} error in Source Maps:`, e2.message);
});
} else {
console.log(`🔥 ${route} pageerror:`, e);
}
Expand Down Expand Up @@ -119,6 +121,12 @@ const crawl = async opt => {
};
process.on("SIGINT", onSigint);

const onUnhandledRejection = error => {
console.log("UnhandledPromiseRejectionWarning", error);
shuttingDown = true;
};
process.on("unhandledRejection", onUnhandledRejection);

const queue = _();
let enqued = 0;
let processed = 0;
Expand Down Expand Up @@ -220,6 +228,7 @@ const crawl = async opt => {
.mergeWithLimit(options.concurrency)
.toArray(async () => {
process.removeListener("SIGINT", onSigint);
process.removeListener("unhandledRejection", onUnhandledRejection);
await browser.close();
onEnd && onEnd();
if (shuttingDown) return reject("");
Expand Down

0 comments on commit 8924f23

Please sign in to comment.