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

"error" event handlers require the error to be handled twice #1274

Closed
Holger-Will opened this issue Apr 14, 2019 · 2 comments

Comments

@Holger-Will
Copy link

commented Apr 14, 2019

What version of standard?

12.0.1

What operating system, Node.js, and npm version?

linux, node 8.4.0 (my min version), npm 6.9.0

What did you expect to happen?

when using an event bases error handler:

this.port.on('error', err => {
  node.warn('an error occurred')
})

i get Expected error to be handled
but when i use

this.port.on('error', err => {
  if (err) {
    node.warn('an error occurred')
  }
})

everything is fine.

this seems superfluous to me. The error handler is only called if there is an error, so err is always an error object.

I think you should not be required to check for the error object in this case.

@stale

This comment has been minimized.

Copy link

commented Jul 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Jul 13, 2019

@stale stale bot closed this Jul 20, 2019

@feross

This comment has been minimized.

Copy link
Member

commented Jul 20, 2019

If you name the variable err then you should use it. You don't need to include it in an if block, though. You can use it in the warning message that you print, like this:

this.port.on('error', err => {
  node.warn('an error occurred ' + err.message)
})

If you don't want to use the error, then don't include an err argument. Do this:

this.port.on('error', () => {
  node.warn('an error occurred')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.