Use ".then(null, Cu.reportError);" with Promise.jsm
Mark Hammond
mhammond at skippinet.com.au
Mon Aug 12 23:44:16 UTC 2013
On 12/08/2013 11:28 PM, David Rajchenbach-Teller wrote:
> On 8/10/13 5:04 AM, Mark Hammond wrote:
>> On 9/08/2013 8:32 PM, David Rajchenbach-Teller wrote:
>>> 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.
>>
>> This concept of a "promise chain" escapes me. I understand that
>> conceptually, promise code should look like:
>>
>> something.then(step1)
>> .then(step2)
>> .then(step3)
>> .then(null, Cu.reportError)
>>
>> One nice promise chain and the final .then() looks reasonable. But
>> every time I try and use promises, they actually end up looking like:
>>
>> something.then(result => {
>> step1.then(result => {
>> step2.then(result => {
>> step3.then(result => {
>> });
>> });
>> });
>> })
>>
>> in that case we have 4 "promise chains". Thus, we need 4 extra
>> .then(null, Cu.reportError) calls, making the code much larger and
>> harder to follow.
>
> That's actually a single chain that promises to return the result of
> step3.then(result => { ... })
> so, with respect to error reporting, fine with me.
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?
[If nothing else though, this thread shows that it's extremely hard to
write code around this that is "obviously correct"]
Cheers,
Mark
More information about the firefox-dev
mailing list