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

Uncaught, unspecified 'error' event #215

Closed
antoine-pous opened this issue May 27, 2017 · 4 comments
Closed

Uncaught, unspecified 'error' event #215

antoine-pous opened this issue May 27, 2017 · 4 comments

Comments

@antoine-pous
Copy link

antoine-pous commented May 27, 2017

Hi !

For the first time i'm facing a problem with EE2, here is the code:

let net = require('net')
let ev = require('eventemitter2').EventEmitter2
let myProject = function(host, port) {
  ev.call(this)
  let self = this
  let socket = net.connect(port, host)
  socket.on("error", function(e) {
    // here
    self.emit("error", "Socket", e.syscall + ' ' + e.errno + ' on ' + e.host + ':' + e.port)
  })
util.inherits(myProject, ev)
exports = module.exports = myProject

Each time i got this error Uncaught, unspecified 'error' event, when i change the event name for any other name the event is correctly emitted.

I don't understand why i have this behavior, this kind of feature works on any other components of my project.

@RangerMauve
Copy link
Contributor

Could you please post the stack trace from the error as well as the version of EE2 you have installed?

@agirorn
Copy link
Contributor

agirorn commented Dec 4, 2017

It seems that if you are not listening on the error event when it is emitted EvenEmmiter will throw this error.

The error can be reproduced like this

const EventEmitter2 = require('eventemitter2').EventEmitter2;
const events = new EventEmitter2();

console.log('sending first error event');
try {
  events.emit('error', 'The error data');
} catch(e) {
  console.log('caught error', e);
}

events.on('error', (error) => { console.log('got error event', error); });
console.log('sending second error event');
try {
  events.emit('error', 'The error data');
} catch(e) {
  console.log('caught error', e);
}
sending first error event
caught error Error: Uncaught, unspecified 'error' event.
    at EventEmitter.emit (/home/agirorn/code/test/node_modules/eventemitter2/lib/eventemitter2.js:398:15)
    at Object.<anonymous> (/home/agirorn/code/test/t.js:6:10)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:383:7)
    at startup (bootstrap_node.js:149:9)
sending second error event
got error event The error data

@RangerMauve
Copy link
Contributor

Thanks for the details, sadly I'm a bit busy at the moment, but a PR seems like it wouldn't be too hard to do and would be very much welcome!

@agirorn
Copy link
Contributor

agirorn commented Dec 9, 2017

I think think this is a similar case to the uncaught promise exception. When it occurs in node.js it is output to the console and the unhandledRejection event is sent. Could this be similar and somehow use the node.js process.on('warning', cb) Event: 'warning' to notify that this occurred and not throw an error that may end up killing the process?

I checked in node 6.12.0 and the process object is an event emitter object and can be used to do this.

process.on('warning', (m) => console.log(`got warning ${m}`));
process.emit('warning', 'test')
=> got warning test
=> true

Would that be an acceptable solution to this?

RangerMauve added a commit that referenced this issue Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants