-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
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.
|
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I appreciate your concern, but it would probably much simpler if you just merged your PR. Just close mine, no worries :)
…On March 4, 2024 7:38:49 PM GMT+01:00, "Josh Goldberg ✨" ***@***.***> wrote:
@JoshuaKGoldberg requested changes on this pull request.
Lovely! 🙌
Requesting changes on the unit test & including column.
> @@ -71,8 +71,11 @@ 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 (err, url, line, colno, error) {
+ if (!error) {
+ error = new Error(err + ' (' + url + ':' + line + ')');
+ }
+ fn(error);
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.
On browser-entry.js:
[Testing] Could you add a unit test too, please?
#5107 has a reference if that's helpful.
--
Reply to this email directly or view it on GitHub:
#5080 (review)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
PR Checklist
958 (which is closed but not really fixed)🐛 Bug: Browser doesn't include call stack for global uncaught errors #5106status: accepting prs
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