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

David Rajchenbach-Teller dteller at mozilla.com
Fri Aug 9 10:32:15 UTC 2013


Furthermore, I *strongly* suggest that we r- any promise chain that does
not report errors, unless there is a comment explaining why we do not.

Cheers,
 David


On 8/9/13 11:10 AM, Paolo Amadini wrote:
> This is a quick reminder to anyone writing or reviewing code that uses
> "Promise.jsm".
> 
> You should check that exceptions aren't swallowed, and this is typically
> done with a logging rejection handler. You should always use the handler
> unless you're handing off the promise to other code. For some examples:
> 
> https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Promise.jsm/Promise#Handling_errors_and_common_pitfalls
> 
> As of now, this amounts to a pattern like:
> 
>   myPromise.then(value => {
>     // ...
>   }).then(null, Components.utils.reportError);
> 
> Or when creating a task without returning the promise:
> 
>   Task.spawn(function () {
>     // yield ...
>   }).then(null, Components.utils.reportError);
> 
> I admit that having to explicitly provide an error handler at the end
> of a promise chain may be considered less than optimal, but for now it
> is the recommended way in new code. We're discussing ways to make it
> less likely that exceptions are swallowed, in bug 902866:
> 
> https://bugzilla.mozilla.org/show_bug.cgi?id=902866
> 
> Please reply in the bug if you have anything to add to the discussion.
> 
> Cheers,
> Paolo
> _______________________________________________
> firefox-dev mailing list
> firefox-dev at mozilla.org
> https://mail.mozilla.org/listinfo/firefox-dev
> 


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



More information about the firefox-dev mailing list