Closed Bug 1362970 Opened 8 years ago Closed 8 years ago

Convert .then(null, ...) to .catch(...)

Categories

(Toolkit :: Async Tooling, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla56
Tracking Status
firefox56 --- fixed

People

(Reporter: Paolo, Assigned: Paolo)

References

(Blocks 1 open bug)

Details

Attachments

(4 files, 3 obsolete files)

We can easily batch convert calls to ".then(null, ...)" and ".then(undefined, ...)" to ".catch(...)", and add an ESLint rule to mandate the use of the latter.
Blocks: 1362972
Attached file catch.js xpcshell script (obsolete) —
Comment on attachment 8865395 [details] [diff] [review] script-generated patch Review of attachment 8865395 [details] [diff] [review]: ----------------------------------------------------------------- ::: addon-sdk/source/lib/sdk/l10n/loader.js @@ +14,5 @@ > > function parseJsonURI(uri) { > return readURI(uri). > then(JSON.parse). > + catch(en(null, function (error) { ...uh?
Attachment #8865395 - Flags: review?(paolo.mozmail)
Attachment #8865395 - Attachment is obsolete: true
(In reply to :Paolo Amadini from comment #3) > > + catch(en(null, function (error) { > > ...uh? That was a bug in my workaround for the broken location of function expressions with a name (I forgot to check that there was a name, so I broke the replacement for anonymous function expression...).
Attachment #8865396 - Attachment is obsolete: true
One thing that cannot be detected by the script is that we have some promise implementations like "deprecated-sync-thenables" that don't support "catch". I would actually suggest running a tryserver build and, if anything is still using these libraries, add a basic "catch" method implementation to them.
(In reply to :Paolo Amadini from comment #6) > I would actually suggest running a tryserver build and, if anything is still > using these libraries, add a basic "catch" method implementation to them. Feel free to use the builds from my try push in comment 4 to test this.
Comment on attachment 8865399 [details] [diff] [review] script-generated patch v2 Review of attachment 8865399 [details] [diff] [review]: ----------------------------------------------------------------- Looks good, below are a few things that may be addressed in a fixup patch. ::: dom/crypto/test/test_WebCrypto.html @@ +495,1 @@ > ); Might want to inline the ");" in these four instances. ::: dom/promise/tests/unit/test_monitor_uncaught.js @@ +106,1 @@ > name: "`then(null, null)`" `catch(null)` ::: services/fxaccounts/tests/xpcshell/test_oauth_grant_client.js @@ +104,5 @@ > }; > > client._Request = new mockResponse(response); > client.getTokenFromAssertion("assertion", "scope") > + .catch(function(e) { The function would need a slightly different indentation, not sure it matters though. ::: toolkit/components/osfile/modules/osfile_async_front.jsm @@ +378,2 @@ > // Fork |promise| to ensure that uncaught errors are reported > + return promise.catch(null); This can just be "return promise.then();" ::: toolkit/components/places/PlacesUtils.jsm @@ +3029,5 @@ > undoTransaction: function CLTXN_undoTransaction() { > // The getLivemark callback may fail, but it is used just to serialize, > // so it doesn't matter. > this._promise = PlacesUtils.livemarks.getLivemark({ id: this.item.id }) > + .catch(null).then( () => { If the comment is correct this is a bug, and this code was meant to be ".catch(() => {})".
Attachment #8865399 - Flags: review?(paolo.mozmail) → review+
(In reply to Florian Quèze [:florian] [:flo] from comment #7) > > I would actually suggest running a tryserver build and, if anything is still > > using these libraries, add a basic "catch" method implementation to them. > > Feel free to use the builds from my try push in comment 4 to test this. Ah, I missed that there were try build links already. Indeed there are failures, so we need to add a new "catch" implementation: A promise chain failed to handle a rejection: - at chrome://mochitests/content/browser/devtools/client/debugger/test/mochitest/browser_dbg_auto-pretty-print-02.js:62 - TypeError: closeDebuggerAndFinish(...).catch is not a function [log…] Funny how these failures were detected by the unhandled rejection code :-)
I discussed this with Paolo over Vidyo, and he'll be handling the next steps here (and I'm still happy to give a hand if needed).
Assignee: florian → paolo.mozmail
Comment on attachment 8878418 [details] Bug 1362970 - Part 1 - Add support for "catch" to "deprecated-sync-thenables". https://reviewboard.mozilla.org/r/149760/#review154478
Attachment #8878418 - Flags: review?(florian) → review+
Comment on attachment 8878419 [details] Bug 1362970 - Part 2 - Script-generated patch to convert .then(null, ...) to .catch(...). https://reviewboard.mozilla.org/r/149762/#review154480 Reviewing a patch of that size is very impactical on mozreview with the pagination... But assuming this is directly the output of the script, r=me with the dom/workers/test/promise_worker.js change reverted. ::: browser/extensions/pdfjs/content/web/viewer.js:1302 (Diff revision 1) > return; > } > this.pdfDocument.getData().then(function getDataSuccess(data) { > var blob = (0, _pdfjsLib.createBlob)(data, 'application/pdf'); > downloadManager.download(blob, url, filename); > - }, downloadByUrl).then(null, downloadByUrl); > + }, downloadByUrl).catch(downloadByUrl); Landing changes to browser/extensions/pdfjs requires notifying the pdfjs developers by opening an issue at https://github.com/mozilla/pdf.js/issues ::: browser/extensions/pocket/content/main.js:567 (Diff revision 1) > } > > function getFirefoxAccountSignedInUser(callback) { > fxAccounts.getSignedInUser().then(userData => { > callback(userData); > - }).then(null, error => { > + }).catch(error => { pocket likely also has its own process to accept changes. ::: browser/extensions/screenshots/webextension/background/takeshot.js:50 (Diff revision 1) > return browser.tabs.create({url: shot.creatingUrl}) > }).then((tab) => { > openedTab = tab; > return uploadShot(shot); > }).then(() => { > - return browser.tabs.update(openedTab.id, {url: shot.viewUrl}).then( > + return browser.tabs.update(openedTab.id, {url: shot.viewUrl}).catch( and screenshots too. ::: dom/workers/test/promise_worker.js:402 (Diff revision 1) > var promise = new Promise(function(resolve, reject) { > reject(42); > }); > > try { > - promise.then(null, function(v) { > + promise.catch(function(v) { The name of the function here (promiseThenNullResolveFunction) makes me think using .then(null was intentional here and should not be changed.
Attachment #8878419 - Flags: review?(florian) → review+
Comment on attachment 8878417 [details] Bug 1362970 - Part 3 - Fix indentation and one misuse of "catch". https://reviewboard.mozilla.org/r/149758/#review154488
Attachment #8878417 - Flags: review?(florian) → review+
(In reply to Florian Quèze [:florian] [:flo] from comment #16) > The name of the function here (promiseThenNullResolveFunction) makes me > think using .then(null was intentional here and should not be changed. Good "catch"! ;-) I've re-generated the patch today and I've reverted the Promise tests and the "extensions" folder. I'm running a tryserver build, and will land the patches if it succeeds: https://treeherder.mozilla.org/#/jobs?repo=try&revision=b62320ad45088323d0fe4edc0b1c596e51af0024
Attachment #8865399 - Attachment is obsolete: true
Eh, I forgot to exclude "deprecated-sync-thenables" when re-generating the scripted patch this time. New attempt: https://treeherder.mozilla.org/#/jobs?repo=try&revision=4d76fb94bc37770b1a60a71656c59e795e68c701
Pushed by paolo.mozmail@amadzone.org: https://hg.mozilla.org/integration/mozilla-inbound/rev/c210c53f73fc Part 1 - Add support for "catch" to "deprecated-sync-thenables". r=florian https://hg.mozilla.org/integration/mozilla-inbound/rev/1075b94a522d Part 2 - Script-generated patch to convert .then(null, ...) to .catch(...). r=florian https://hg.mozilla.org/integration/mozilla-inbound/rev/e8a9a2014b79 Part 3 - Fix indentation and one misuse of "catch". r=florian
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: