Closed Bug 1845691 Opened 2 years ago Closed 2 years ago

catch ("Additional precaution to be entirely sure that we cannot reject.") does not work

Categories

(Toolkit :: Async Tooling, defect)

defect

Tracking

()

RESOLVED FIXED
117 Branch
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.

See Also: → 1845695

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: nobody → rob
Status: NEW → ASSIGNED

(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

Flags: needinfo?(rob)
See Also: → 1845725

(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

Flags: needinfo?(rob)
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/95c00823b834 Fix broken catch() in AsyncShutdown r=Gijs
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 117 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: