From 02f54c6c57f5a3e0be3a44e8e5ca1db98b8dbc8f Mon Sep 17 00:00:00 2001 From: johnjbarton Date: Sat, 4 Aug 2018 09:15:16 -0700 Subject: [PATCH] fix(server): Exit clean on unhandledRejections. (#3092) Add a handler for unhandledRejections, log error and disconnect all, then exit. Also remove broken, untested rejection handler in middleware. Prior to #3064, this block was probably unreachable; the arguments to serveStaticFile are incorrect. --- lib/middleware/karma.js | 8 -------- lib/server.js | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index 5b4ac8718..211b53424 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -236,14 +236,6 @@ function createKarmaMiddleware ( .replace('%MAPPINGS%', mappings) .replace('\n%X_UA_COMPATIBLE%', getXUACompatibleMetaElement(request.url)) }) - }, function (errorFiles) { - serveStaticFile(requestUrl, response, function (data) { - common.setNoCacheHeaders(response) - return data.replace('%SCRIPTS%', '').replace('%CLIENT_CONFIG%', '').replace('%MAPPINGS%', - 'window.__karma__.error("TEST RUN WAS CANCELLED because ' + - (errorFiles.length > 1 ? 'these files contain' : 'this file contains') + - ' some errors:\\n ' + errorFiles.join('\\n ') + '");') - }) }) } else if (requestUrl === '/context.json') { return filesPromise.then(function (files) { diff --git a/lib/server.js b/lib/server.js index 1b440231c..043c8a29c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -353,6 +353,11 @@ class Server extends KarmaEventEmitter { this.log.error(error) disconnectBrowsers(1) }) + + processWrapper.on('unhandledRejection', (error) => { + this.log.error(error) + disconnectBrowsers(1) + }) } _detach (config, done) {