-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Closed
Labels
questionIssues that look for answers.Issues that look for answers.
Description
- Version: 8.6.0
- Platform: darwin
- Subsystem:
I'm not sure is a "feature" or "bug", but use case is messy.
const EventEmitter = require('events').EventEmitter;
const Spawn = require('child_process').spawn;
const EVENTS = {
ERROR: 'error'
};
class Service extends EventEmitter{
run(){
let _spawn = Spawn('badcommand', []).on('error', (error) => {
console.log(error);
});
}
}
(new Service()).run();
Expected result: exit code 0
because error event is handled.
But I want to trigger "my" event also:
const EventEmitter = require('events').EventEmitter;
const Spawn = require('child_process').spawn;
const EVENTS = {
ERROR: 'error'
};
class Service extends EventEmitter{
run(){
let _spawn = Spawn('badcommand', []).on('error', (error) => {
this.emit(EVENTS.ERROR, error); //<--- Here I want to trigger error event of my service
});
}
}
(new Service()).run();
But now result is: exit code 1
- application is crashed within Unhandled 'error' event
Simple changing of event's name fix it:
const EventEmitter = require('events').EventEmitter;
const Spawn = require('child_process').spawn;
const EVENTS = {
ERROR: 'error'
};
class Service extends EventEmitter{
run(){
let _spawn = Spawn('badcommand', []).on('error', (error) => {
this.emit('ServiceError', error); //<--- Here I want to trigger error event of my service
});
}
}
(new Service()).run();
And again I have exit code 0
as it should be.
So, is a bug? Or feature? Why I cannot use same naming for events even I don't inherite from spawn.
If it's some kind of specific it would be great to have some more informative logs in console for such cases.
Thanks.
Metadata
Metadata
Assignees
Labels
questionIssues that look for answers.Issues that look for answers.