Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use original Error object for uncaught errors when provided in browser #5080

Closed
wants to merge 1 commit into from

Conversation

karyon
Copy link

@karyon karyon commented Jan 18, 2024

PR Checklist

Overview

In case of uncaught errors, mocha would print only the error message, which is essentially the first line of the stack trace. The actual stack trace was unused. This is essentially #2403 which was closed for inactivity.

Here's a fiddle demonstrating the problem: https://jsfiddle.net/Lru1q4n6/ (updated from the PR above). Unfortunately, I don't know how to demonstrate the fix there. Of course it does work locally, I used this fix to debug our tests.

Co-authored-by: @mgiuffrida

In case of uncaught errors, mocha would print the error message, which is essentially the first line of the stack trace. The actual stack trace was unused.
Copy link

linux-foundation-easycla bot commented Jan 18, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: karyon / name: Johannes Linke (0d4042f)

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely! 🙌

Requesting changes on the unit test & including column.

if (!error) {
error = new Error(err + ' (' + url + ':' + line + ')');
}
fn(error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! I'd filed #5106 before seeing this PR. Great. I'll close that one since this once came first.

[Feature] What do you think about including ':' + col too, per https://github.com/mochajs/mocha/pull/5107/files#diff-c282db01f80ee266af40ae81278d9d99177c763ae242fdeb38ee33c603598a2fR75 ?

Request adding it in as a new nicety, unless you know of a reason not to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Testing] Could you add a unit test too, please?

#5107 has a reference if that's helpful.

@JoshuaKGoldberg JoshuaKGoldberg added status: waiting for author waiting on response from OP - more information needed semver-patch implementation requires increase of "patch" version number; "bug fixes" labels Mar 4, 2024
@JoshuaKGoldberg JoshuaKGoldberg changed the title Use original Error object for uncaught errors when provided fix: use original Error object for uncaught errors when provided in browser Mar 4, 2024
@karyon
Copy link
Author

karyon commented Mar 5, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch implementation requires increase of "patch" version number; "bug fixes" status: waiting for author waiting on response from OP - more information needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants