Skip to content

Commit

Permalink
fix: include stack trace for global uncaught errors
Browse files Browse the repository at this point in the history
This PR closes mochajs#5106
  • Loading branch information
ergunsh committed May 6, 2024
1 parent 99601da commit a4a0807
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions browser-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ process.listenerCount = function (name) {

process.on = function (e, fn) {
if (e === 'uncaughtException') {
global.onerror = function (err, url, line) {
fn(new Error(err + ' (' + url + ':' + line + ')'));
global.onerror = function (event, url, line, col, actualError) {
const err = new Error(event + ' (' + url + ':' + line + ':' + col + ')');
try {
err.stack = actualError.stack;
} catch (ignored) {
// some environments do not take kindly to monkeying with the stack
}

fn(err);
return !mocha.options.allowUncaught;
};
uncaughtExceptionHandlers.push(fn);
Expand Down

0 comments on commit a4a0807

Please sign in to comment.