baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript
https://baconjs.github.io
MIT License
6.47k stars 330 forks source link

Errors are swallowed when using fromPromise(A+ promise) #511

Closed AlexGalays closed 9 years ago

AlexGalays commented 9 years ago

When in dev mode, it would be very useful to have a global, catch-all error handler since bacon swallow all errors. A tiny error in a map() somewhere downstream, and nothing happens, no stream is consumed, no error is thrown.

It could be used as follow:

if (process.env.dev)
  Bacon.onError = e -> console.error(e);
raimohanska commented 9 years ago

No it doesnt swallow all errors does it!? There was a bug but with latest version there should not be such behavior

AlexGalays commented 9 years ago

I'm using the latest version :(

raimohanska commented 9 years ago

And you say exceptions are hidden? Any example?

AlexGalays commented 9 years ago

Well, the good news is I can't reproduce it. Perhaps I was not generating errors but only undefined values...

AlexGalays commented 9 years ago

Ok, I reproduced it. It seems to involve fromPromise even though the error is thrown in a mapped stream. I guess that's because all the downstream user code is called within the then of the A+ promise, which catches any error.

Try this at requirebin:

var Bacon = require('baconjs');
var Q = require('q');

var as = Bacon.fromArray([1, 2, 3]).flatMap(function(num) { return Bacon.fromPromise(Q(num)) });
var bs = as.scan(10, function(a, b) { return a() + b }); // a is a Number but a() doesn't throw an error

bs.onValue(function(b) {
  console.log(b);
});
raimohanska commented 9 years ago

true! needs investigation.

raimohanska commented 9 years ago

oh, it's Q that's swallowing the exception, not Bacon :)

AlexGalays commented 9 years ago

Yes and no :p

Q or any A+ promise implementation will by design swallow an exception in a then success handler if no other action is taken (in the case of Q, you would have to use done() to advice the promise chain is over and all errors have been handled).

Since bacon only relies on the presence of a 'then' function, I think the only action possible is for it to add a try-catch that call the same thing as the error handler.

raimohanska commented 9 years ago

This is duplicate to #501

raimohanska commented 9 years ago

Fixed in 0.7.50