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

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 Medium priority.
Krinkle moved this task from Inbox to Accepted Enhancement on the MediaWiki-ResourceLoader board.
Krinkle subscribed.

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

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

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