From 241e1a81f6fccf53b92e1db34e2fca15b0bcd694 Mon Sep 17 00:00:00 2001 From: Ben Demboski Date: Wed, 10 Aug 2022 19:50:17 -0700 Subject: [PATCH] Don't exit process when requesting a failed build If the most recent build failed and an HTTP request came in, the history middleware would throw an uncaught exception causing the process to exit. Instead, catch and ignore. --- lib/tasks/server/middleware/history-support/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tasks/server/middleware/history-support/index.js b/lib/tasks/server/middleware/history-support/index.js index 3d31dc14ad..0635fa461a 100644 --- a/lib/tasks/server/middleware/history-support/index.js +++ b/lib/tasks/server/middleware/history-support/index.js @@ -49,7 +49,16 @@ class HistorySupportAddon { app.use(async (req, _, next) => { try { - const results = await watcher; + let results; + try { + results = await watcher; + } catch (e) { + // This means there was a build error, so we won't actually be serving + // index.html, and we have nothing to do. We have to catch it here, + // though, or it will go uncaught and cause the process to exit. + return; + } + if (this.shouldHandleRequest(req, options)) { let assetPath = req.path.slice(baseURL.length); let isFile = false;