This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 234
Improve error message when .use() not called for a Plugin #270
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
edmorley
added a commit
that referenced
this pull request
Jul 19, 2020
Previously if `.tap()` was called for a plugin that didn't exist, the `.tap()` call would succeed, but the `.toConfig()` would fail later with: `TypeError: Cannot read property '__expression' of undefined` This scenario can typically occur when trying to customise a plugin added by a previous preset (where the preset only sometimes adds the plugin, such as in development), and forgetting to add a conditional using `.has()` before calling `.tap()`. Whilst #270 changes that exception to a slightly more useful error message, it is still only shown at the time of the `.toConfig()`, where it's much harder to debug the cause. Now the `.tap()` call itself will show the error: `Error: Cannot call .tap() on a plugin that has not yet been defined. Call plugin('foo').use(<Plugin>) first` Whilst this error check does technically break the (unlikely) scenario of calling `.tap()` in a preset before the plugin is defined, that ordering was already broken, since the `.tap()`'s args would have been overwritten by the subsequent preset. Fixes #125.
eliperelman
approved these changes
Jul 20, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
Previously if `.toConfig()` was called when a plugin was only partially configured, it raised with the unhelpful: `TypeError: Cannot read property '__expression' of undefined` Now the scenario results in an Error of form: `Invalid plugin configuration: plugin('foo').use(<Plugin>) was not called to specify the plugin` Or for minimizer plugins: `Invalid optimization.minimizer configuration: optimization.minimizer('foo').use(<Plugin>) was not called to specify the plugin` Fixes scenario 1 in: #204 (comment)
edmorley
force-pushed
the
edmorley-toConfig-validate-plugin
branch
from
July 20, 2020 15:41
c3764b6
to
d7b641f
Compare
edmorley
added a commit
that referenced
this pull request
Jul 20, 2020
Previously if `.tap()` was called for a plugin that didn't exist, the `.tap()` call would succeed, but the `.toConfig()` would fail later with: `TypeError: Cannot read property '__expression' of undefined` This scenario can typically occur when trying to customise a plugin added by a previous preset (where the preset only sometimes adds the plugin, such as in development), and forgetting to add a conditional using `.has()` before calling `.tap()`. Whilst #270 changes that exception to a slightly more useful error message, it is still only shown at the time of the `.toConfig()`, where it's much harder to debug the cause. Now the `.tap()` call itself will show the error: `Error: Cannot call .tap() on a plugin that has not yet been defined. Call plugin('foo').use(<Plugin>) first` Whilst this error check does technically break the (unlikely) scenario of calling `.tap()` in a preset before the plugin is defined, that ordering was already broken, since the `.tap()`'s args would have been overwritten by the subsequent preset. Fixes #125.
edmorley
added a commit
that referenced
this pull request
Jul 20, 2020
Previously if `.tap()` was called for a plugin that didn't exist, the `.tap()` call would succeed, but the `.toConfig()` would fail later with: `TypeError: Cannot read property '__expression' of undefined` This scenario can typically occur when trying to customise a plugin added by a previous preset (where the preset only sometimes adds the plugin, such as in development), and forgetting to add a conditional using `.has()` before calling `.tap()`. Whilst #270 changes that exception to a slightly more useful error message, it is still only shown at the time of the `.toConfig()`, where it's much harder to debug the cause. Now the `.tap()` call itself will show the error: `Error: Cannot call .tap() on a plugin that has not yet been defined. Call plugin('foo').use(<Plugin>) first` Whilst this error check does technically break the (unlikely) scenario of calling `.tap()` in a preset before the plugin is defined by a later preset, that ordering was already broken, since the `.tap()`'s args would have been overwritten by the subsequent preset. Fixes #125.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously if
.toConfig()
was called when a plugin was only partially configured, it raised with the unhelpful:TypeError: Cannot read property '__expression' of undefined
Now the scenario results in an error of form:
Error: Invalid plugin configuration: plugin('foo').use(<Plugin>) was not called to specify the plugin
Or for minimizer plugins:
Error: Invalid optimization.minimizer configuration: optimization.minimizer('foo').use(<Plugin>) was not called to specify the plugin
Fixes scenario 1 in:
#204 (comment)