Skip to content

Conversation

@ctide
Copy link
Contributor

eventemitter: clarify error message

Update error message that's thrown when no error listeners are attached to an emitter. This would have been trivial to debug if I had understood what 'unspecified error' was supposed to mean. Once I went looking at the source, and saw the comment on 149, it was easy to fix.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

eventemitter

Description of change

Update error message that's thrown when no error listeners are attached to an emitter. This would have been trivial to debug if I had understood what 'unspecified error' was supposed to mean. Once I went looking at the source, and saw the comment on 149, it was easy to fix.

@nodejs-github-botnodejs-github-bot added events Issues and PRs related to the events subsystem / EventEmitter. lts-watch-v6.x labels Dec 21, 2016
@cjihrigcjihrig added the semver-major PRs that contain breaking changes and should be released in the next major version. label Dec 21, 2016
lib/events.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is too long.

lib/events.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is too long.

Copy link
Contributor

@sam-githubsam-github left a comment

Choose a reason for hiding this comment

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

Unspecified is confusing, yes, but I don't think the text is an improvement. I can think of 2 other ways to avoid the abort that don't involve listening for the error (the 'uncaughtException' handler and domains), so the text is both too long, and not correct.

How about just 'Uncaught "error" event'?

@ctide
Copy link
ContributorAuthor

Fixed, sorry, didn't realize that running tests didn't run the linter as well.

@ctide
Copy link
ContributorAuthor

Sure, that's reasonable. Unspecified was what really threw me off. I'll update and rebase.

@sam-github
Copy link
Contributor

Also, needs a unit test - and yes, I know, it should have already had one, sorry!

@ctide
Copy link
ContributorAuthor

Seemed like a message was the cleanest way to add a test for this. If that's not the right approach, let me know and I can update!

Copy link
Contributor

Choose a reason for hiding this comment

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

[object Object] is probably not the desired output.

@cjihrig
Copy link
Contributor

You don't need a message test. There is almost certainly a test that already exercises this behavior. You would just need to add an assertion on the error message in such a test.

@ctide
Copy link
ContributorAuthor

OK, found the real test and just updated the regex to include the changes.

lib/events.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

I think either the parens should be dropped or the colon removed.

@mscdex
Copy link
Contributor

IMHO I think "uncaught" is a bit of a misnomer, since to me it sounds like the error was thrown because of a missing try-catch or something. What about "unhandled" instead?

@ctide
Copy link
ContributorAuthor

Yeah, unhandled is more accurate than uncaught. Will push an update in a minute that changes it to that.

Copy link
Contributor

Choose a reason for hiding this comment

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

People should not be emitting strings or other things, even though we technically support it. So, in most cases, we'll print the rather unhelpful [object Object], like in your previous test, right?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Certainly in all of my team's code, we pass an object to the emitter so it would just spit that out, yes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd opt to just not try to print the error. You could use util.format(), but it prints the whole stack trace for errors, so it's kind of loud.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, I just omitted it and made the test reflect a real world use case slightly better.

@ctide
Copy link
ContributorAuthor

@Trott: I think maybe I was just on the wrong branch. It was my first time pulling down and running the node tests. I tried to recreate it to see if it was something with first time configuring & running tests, and it ran the linter.

Copy link
Member

Choose a reason for hiding this comment

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

Nit: how about using ^Error: Unhandled "error" event$? Pointing this out only because other tests do this.

@italoacasas
Copy link

@joaocgreis
Copy link
Member

Re-run of arm-fanned because of the RPi1 failures: https://ci.nodejs.org/job/node-test-commit-arm-fanned/6082/

Copy link
Member

@jasnelljasnell left a comment

Choose a reason for hiding this comment

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

This LGTM but might have broader impact than expected. @nodejs/ctc thoughts?

lib/events.js Outdated
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure it's a good idea to remove the last part. I understand that if you emit a plain object, it will print [object Object] but it seems logical for the "error" event to emit an Error and in this case it would print the error message correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree.

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, I would prefer that we keep the er in the message

lib/events.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Prefer const over var wherever possible.

@jasnell
Copy link
Member

@nodejs/ctc ... any further thoughts on this one?
@ctide ... if you'd like to pursue this can you please give it a quick rebase?

Update error message that's thrown when no error listeners are attached to an emitter. This would have been trivial to debug if I had understood what 'unspecified error' was supposed to mean. Once I went looking at the source, and saw the comment on 149, it was easy to fix.
@ctide
Copy link
ContributorAuthor

Rebased, and a few minor things based on the other feedback (adding er back, changing var to const, using fat arrow functions in the test instead.)

@jasnell
Copy link
Member

@sam-github@cjihrig ... PTAL

@jasnell
Copy link
Member

jasnell pushed a commit that referenced this pull request Mar 24, 2017
Update error message that's thrown when no error listeners are attached to an emitter. PR-URL: #10387 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Italo A. Casas <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
@jasnell
Copy link
Member

Landed in 2141d37

@jasnelljasnell changed the title Update events.jsevents: update and clarify error messageMar 24, 2017
@jasnelljasnell closed this Mar 24, 2017
@jasnelljasnell mentioned this pull request Apr 4, 2017
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eventsIssues and PRs related to the events subsystem / EventEmitter.semver-majorPRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

13 participants

@ctide@sam-github@cjihrig@mscdex@Trott@italoacasas@joaocgreis@jasnell@evanlucas@thefourtheye@lpinca@targos@nodejs-github-bot