fix error message and stack in Firefox

in Firefox stack doesn't include the message
This commit is contained in:
Tobias Koppers 2019-06-12 15:28:45 +02:00
parent acf2c2d4b1
commit a1d45671c1
5 changed files with 19 additions and 13 deletions

View File

@ -40,10 +40,10 @@ if (module.hot) {
"warning", "warning",
"[HMR] Cannot apply update. Need to do a full reload!" "[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(); window.location.reload();
} else { } else {
log("warning", "[HMR] Update failed: " + (err.stack || err.message)); log("warning", "[HMR] Update failed: " + log.formatError(err));
} }
}); });
}; };

View File

@ -45,3 +45,15 @@ module.exports.groupEnd = logGroup(groupEnd);
module.exports.setLogLevel = function(level) { module.exports.setLogLevel = function(level) {
logLevel = 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;
}
};

View File

@ -72,12 +72,9 @@ if (module.hot) {
"warning", "warning",
"[HMR] Cannot check for update. Need to do a full reload!" "[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 { } else {
log( log("warning", "[HMR] Update check failed: " + log.formatError(err));
"warning",
"[HMR] Update check failed: " + (err.stack || err.message)
);
} }
}); });
}; };

View File

@ -23,13 +23,10 @@ if (module.hot) {
var status = module.hot.status(); var status = module.hot.status();
if (["abort", "fail"].indexOf(status) >= 0) { if (["abort", "fail"].indexOf(status) >= 0) {
log("warning", "[HMR] Cannot apply update."); 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!"); log("warning", "[HMR] You need to restart the application!");
} else { } else {
log( log("warning", "[HMR] Update failed: " + log.formatError(err));
"warning",
"[HMR] Update failed: " + (err.stack || err.message)
);
} }
}); });
} }

View File

@ -37,7 +37,7 @@ if (module.hot) {
var status = module.hot.status(); var status = module.hot.status();
if (["abort", "fail"].indexOf(status) >= 0) { if (["abort", "fail"].indexOf(status) >= 0) {
log("warning", "[HMR] Cannot apply update."); 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!"); log("warning", "[HMR] You need to restart the application!");
} else { } else {
log("warning", "[HMR] Update failed: " + (err.stack || err.message)); log("warning", "[HMR] Update failed: " + (err.stack || err.message));