Page MenuHomePhabricator

Add custom error message when trying to use a component not listed in codexComponents
Closed, ResolvedPublic

Description

Currently, when you do const { CdxButton } = require( './codex.js' );, but you didn't list CdxButton in the codexComponents array in the module definition, you won't get an error on that line, and you'll eventually get a somewhat confusing error because CdxButton is undefined.

Instead, we would like to throw a clearer error message that makes clear to the developer what they did wrong and how they can fix it. We could accomplish this by wrapping the object returned by CodexModule in a Proxy.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 983525 had a related patch set uploaded (by Tyhopp; author: Tyhopp):

[mediawiki/core@master] CodexModule: Throw helpful error if component not listed in module definition

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

Change 983525 merged by jenkins-bot:

[mediawiki/core@master] CodexModule: Throw helpful error if component not listed in module definition

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

Thanks @CCiufo-WMF, happy to contribute! Also thanks @Catrope for guiding me through the unfamiliar territory.

Change 984663 had a related patch set uploaded (by Tyhopp; author: Tyhopp):

[mediawiki/core@master] CodexModule: Handle missing or empty codex component definitions

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

Change 984663 merged by jenkins-bot:

[mediawiki/core@master] CodexModule: Handle empty codex component definitions

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