Use ".then(null, Cu.reportError);" with Promise.jsm

David Rajchenbach-Teller dteller at mozilla.com
Tue Aug 13 09:40:55 UTC 2013


On Tue Aug 13 01:44:16 2013, Mark Hammond wrote:
> But isn't it true that exceptions in any of those bodies would remain
> unreported?  ie, if the inner was changed to:
>
>           step3.then(result => {
>             throw "oh no";
>           });
>
> wouldn't it need to be:
>
>           step3.then(result => {
>             throw "oh no";
>           }).then(null, Cu.reportError);
>
> to see that exception?  And thus each of the .then() calls above needs
> the trailing .then()?  If so, I'm not sure how the original version
> could be "fine" in this regard?

Works for me. The error in step3 is reported with the outer |then|. I'm
not completely sure that |Cu.reportError| works when it's not bound to
|Cu|, though.


Now, the real issue appears if you have

step1.then(result => {
    step2(); // That's a promise but we ignore the result
    return step3();
  }
);

Here, step2 is not in the chain, hence any error thrown by step2 is ignored.

> [If nothing else though, this thread shows that it's extremely hard to
> write code around this that is "obviously correct"]

Well, that's why we have Task.jsm.
Well, really, if you have the slightest doubt, please use Task.jsm. It
makes everything much, much easier.

Cheers,
 David


-- 
David Rajchenbach-Teller, PhD
 Performance Team, Mozilla
-- 
David Rajchenbach-Teller, PhD
 Performance Team, Mozilla



More information about the firefox-dev mailing list