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

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

Open
tupini07 opened this issue Aug 11, 2016 · 5 comments
Open

Comments

@tupini07
Copy link

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?

@derhuerst
Copy link

See nodejs/node#830.

@nijikokun
Copy link
Owner

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

@nijikokun
Copy link
Owner

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.

@tupini07
Copy link
Author

Yes a warning sound like the best idea

@therebelrobot
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants