From a1d45671c1f0cf6d41347718e5797c8ec50bc280 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 12 Jun 2019 15:28:45 +0200 Subject: [PATCH] fix error message and stack in Firefox in Firefox stack doesn't include the message --- hot/dev-server.js | 4 ++-- hot/log.js | 12 ++++++++++++ hot/only-dev-server.js | 7 ++----- hot/poll.js | 7 ++----- hot/signal.js | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/hot/dev-server.js b/hot/dev-server.js index 682a47f84..f396a34af 100644 --- a/hot/dev-server.js +++ b/hot/dev-server.js @@ -40,10 +40,10 @@ if (module.hot) { "warning", "[HMR] Cannot apply update. Need to do a full reload!" ); - log("warning", "[HMR] " + (err.stack || err.message)); + log("warning", "[HMR] " + log.formatError(err)); window.location.reload(); } else { - log("warning", "[HMR] Update failed: " + (err.stack || err.message)); + log("warning", "[HMR] Update failed: " + log.formatError(err)); } }); }; diff --git a/hot/log.js b/hot/log.js index 0d05673f8..32a1c69b1 100644 --- a/hot/log.js +++ b/hot/log.js @@ -45,3 +45,15 @@ module.exports.groupEnd = logGroup(groupEnd); module.exports.setLogLevel = function(level) { logLevel = level; }; + +module.exports.formatError = function(err) { + var message = err.message; + var stack = err.stack; + if (!stack) { + return message; + } else if (stack.indexOf(message) < 0) { + return message + "\n" + stack; + } else { + return stack; + } +}; diff --git a/hot/only-dev-server.js b/hot/only-dev-server.js index 043f2430b..12df4687e 100644 --- a/hot/only-dev-server.js +++ b/hot/only-dev-server.js @@ -72,12 +72,9 @@ if (module.hot) { "warning", "[HMR] Cannot check for update. Need to do a full reload!" ); - log("warning", "[HMR] " + (err.stack || err.message)); + log("warning", "[HMR] " + log.formatError(err)); } else { - log( - "warning", - "[HMR] Update check failed: " + (err.stack || err.message) - ); + log("warning", "[HMR] Update check failed: " + log.formatError(err)); } }); }; diff --git a/hot/poll.js b/hot/poll.js index 8193db01f..81d33e7c7 100644 --- a/hot/poll.js +++ b/hot/poll.js @@ -23,13 +23,10 @@ if (module.hot) { var status = module.hot.status(); if (["abort", "fail"].indexOf(status) >= 0) { log("warning", "[HMR] Cannot apply update."); - log("warning", "[HMR] " + (err.stack || err.message)); + log("warning", "[HMR] " + log.formatError(err)); log("warning", "[HMR] You need to restart the application!"); } else { - log( - "warning", - "[HMR] Update failed: " + (err.stack || err.message) - ); + log("warning", "[HMR] Update failed: " + log.formatError(err)); } }); } diff --git a/hot/signal.js b/hot/signal.js index 24c4f5cb3..63bfdd650 100644 --- a/hot/signal.js +++ b/hot/signal.js @@ -37,7 +37,7 @@ if (module.hot) { var status = module.hot.status(); if (["abort", "fail"].indexOf(status) >= 0) { log("warning", "[HMR] Cannot apply update."); - log("warning", "[HMR] " + (err.stack || err.message)); + log("warning", "[HMR] " + log.formatError(err)); log("warning", "[HMR] You need to restart the application!"); } else { log("warning", "[HMR] Update failed: " + (err.stack || err.message));