catch ("Additional precaution to be entirely sure that we cannot reject.") does not work
Categories
(Toolkit :: Async Tooling, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox117 | --- | fixed |
People
(Reporter: robwu, Assigned: robwu)
References
Details
Attachments
(1 file)
There is a promise variable that is expected to settle and set isPhaseEnd to true at https://searchfox.org/mozilla-central/rev/bf272a7be6fef0e91bde01dfe1f68403d8fbc237/toolkit/components/asyncshutdown/AsyncShutdown.sys.mjs#563-565,570,575,577
promise = ...
.catch
// Additional precaution to be entirely sure that we cannot reject.
();
...
promise.then(() => (isPhaseEnd = true)); // This promise cannot reject
The above was added in bug 1249590 in a clear attempt to "bullet-proof" it, but does not work, because .catch() without a function parameter does not swallow the error. Consequently, it is possible for isPhaseEnd to never be set to true. This might be a cause of bug 1442971.
As a comparable isolated test case, just run Promise.reject(1).catch() from the console and you'll see that the result is still a rejected promise.
The corrected version should pass a function (even a dummy one) or to use promise.finally instead of .catch() + .promise.then.
| Assignee | ||
Comment 1•2 years ago
|
||
| Assignee | ||
Comment 2•2 years ago
|
||
I looked up other potential callers and filed bug 1845695 as a follow-up for another suspicious case.
There is also this useless .catch(), but due to an earlier .catch(ex => ex) it doesn't break anything: https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/browser/components/newtab/content-src/components/Card/Card.jsx#64,66
| Assignee | ||
Updated•2 years ago
|
Comment 3•2 years ago
|
||
(In reply to Rob Wu [:robwu] from comment #2)
I looked up other potential callers and filed bug 1845695 as a follow-up for another suspicious case.
Could we have a linting rule to, uh, catch this, in future? :-)
There is also this useless
.catch(), but due to an earlier.catch(ex => ex)it doesn't break anything: https://searchfox.org/mozilla-central/rev/00e6644d0db8acf9372702324151b8077a3d2bb7/browser/components/newtab/content-src/components/Card/Card.jsx#64,66
| Assignee | ||
Comment 4•2 years ago
|
||
(In reply to :Gijs (he/him) from comment #3)
(In reply to Rob Wu [:robwu] from comment #2)
I looked up other potential callers and filed bug 1845695 as a follow-up for another suspicious case.
Could we have a linting rule to, uh, catch this, in future? :-)
I filed bug 1845725 for an eslint rule to catch catch calls
Comment 6•2 years ago
|
||
| bugherder | ||
Description
•