breeze icon indicating copy to clipboard operation
breeze copied to clipboard

If error is thrown but no 'catch' is defined then nothing happens

Open tupini07 opened this issue 8 years ago • 5 comments

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?

tupini07 avatar Aug 11 '16 22:08 tupini07

See nodejs/node#830.

derhuerst avatar Aug 11 '16 22:08 derhuerst

@derhuerst because the catch could be attached at a later time.

nijikokun avatar Aug 11 '16 23:08 nijikokun

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.

nijikokun avatar Aug 11 '16 23:08 nijikokun

Yes a warning sound like the best idea

tupini07 avatar Aug 12 '16 17:08 tupini07

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.

therebelrobot avatar Aug 17 '16 23:08 therebelrobot