breeze
breeze copied to clipboard
If error is thrown but no 'catch' is defined then nothing happens
Let's say that I have this code:
let breeze = require('breeze');
let flow = breeze(next => next(null, 'something'));
flow.then((n, v) => {
nonDeclaredVar += 1; //This throws: ReferenceError: nonDeclaredVar is not defined
});
If I run this I won't get any error or message saying that nonDeclaredVar
has not been declared, actually I won't get any messages at all, the program will just exit silently.
However if I specify a catch
like this:
let breeze = require('breeze');
let flow = breeze(next => next(null, 'something'));
flow.then((n, v) => {
nonDeclaredVar += 1;
});
flow.catch(err => {
console.log('something happened');
});
Then I will get something happened
printed to the console, which is what I expect would happen.
I think that if there isn't an error handler then the error should be allowed to bubble up.
What do you think? Is there any reason for not doing anything when an error is thrown and no catch is specified?
See nodejs/node#830.
@derhuerst because the catch could be attached at a later time.
We would have to determine whether the step system has a handler attached or not, at runtime.
When a step is invoked, if there is no handler attached, it will throw an error, and potentially cause an issue within a users application, and must be documented thoroughly.
I much prefer to keep the error until a handler is attached and invoke upon attachment, to ensure that the user's application runs without issue.
A warning that no handler is attached on uncaught error seems like a reasonable solution.
Yes a warning sound like the best idea
If an error is thrown and it's not being handled anywhere, my expectation would be to have the application bail with an Uncaught Error
being thrown. If someone using breeze isn't properly handling errors, it should be seen as a critical application architecture issue, and should enforce proper usage. That's honestly one of my biggest hangups with native Promises, that if you don't put in a catch or don't implement that catch properly, errors are lost to the ethos.