It is impossible to catch ENOENT error
opened this issue · comments
It might happen that the developer installing an application using this package forgot to install kafkacat, because he doesn't RTFM.
In such case, he receives this error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:1001:11)
at Process.ChildProcess._handle.onexit (child_process.js:792:34)
Which is not helpful at all.
What I would like him to see:
Error: missing `kafkacat` binary. Please make sure `kafkacat` is installed and present in your $PATH. Follow the manual here: https://github.com/edenhill/kafkacat
But, I don't know how. What I tried:
consumer = kafkacat.createConsumeStream(consumerOptions)
consumer.on('error', function(err) { /* not called */ }
Sure, it is possible to use process.on('uncaughtException', onError)
and filter all ENOENT
, but that will report all ENOENT exceptions as "missing kafkacat dependency".
How do I catch the right error?
Another idea: try to spawn('kafkacat')
once before calling kafkacat itself and see if it fails. But that would better be solved in the library itself.
I'm still not sure why
kc.on('error', kc.stdout.emit.bind(null, 'error'))
Doesn't propagate errors correctly.