Page MenuHomePhabricator

mw.loader.using() should reject promise instead of throwing on an unknown module
Closed, ResolvedPublic

Description

mw.loader.using() should not throw exceptions when asked to load a non-existent module.

mw.loader.using( 'foo' ).then(
  function () { console.log( 'Loaded!' ); },
  function () { console.log( 'Failed.' ); }
);

Expected: "Failed." is logged to the console.

Actual: Uncaught Error: Unknown dependency: foo

My use case is creating a soft dependency on TitleBlacklist by attempting to load the 'mediawiki.api.titleblacklist' module and assuming nothing is blacklisted if the load fails.

mw.loader.load() doesn't throw an exception, but it doesn't have a callback/promise, so it's useless for me.

Event Timeline

matmarex created this task.Apr 2 2016, 1:48 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 2 2016, 1:48 PM
Krinkle renamed this task from mw.loader.using() should not throw exceptions when asked to load a non-existent module to mw.loader.using() should reject promise instead of throwing on an unknown module.EditedApr 14 2016, 7:11 PM
Krinkle triaged this task as Normal priority.
Krinkle moved this task from Inbox to Accepted: Enhancement on the MediaWiki-ResourceLoader board.
Krinkle added a subscriber: Krinkle.

Agreed. Patch is welcome.

Change 322150 had a related patch set uploaded (by Krinkle):
mw.loader: For using() errors, reject Promise instead of throwing

https://gerrit.wikimedia.org/r/322150

Krinkle claimed this task.Nov 17 2016, 9:00 PM
Krinkle added a project: Performance-Team.
Krinkle moved this task from Accepted: Enhancement to Assigned on the MediaWiki-ResourceLoader board.
Peter added a subscriber: Peter.Nov 17 2016, 9:01 PM
Krinkle moved this task from Inbox to Doing on the Performance-Team board.Nov 17 2016, 9:33 PM

Change 322150 merged by jenkins-bot:
mw.loader: For using() errors, reject Promise instead of throwing

https://gerrit.wikimedia.org/r/322150

matmarex closed this task as Resolved.Nov 18 2016, 12:23 PM
matmarex removed a project: Patch-For-Review.