Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Improve error message when .use() not called for a Plugin #270

Merged
merged 1 commit into from
Jul 20, 2020

Conversation

edmorley
Copy link
Member

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)

@edmorley edmorley added the bug label Jul 19, 2020
@edmorley edmorley self-assigned this Jul 19, 2020
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.
@edmorley edmorley requested a review from a team July 19, 2020 18:27
@edmorley edmorley added enhancement and removed bug labels Jul 19, 2020
Copy link
Member

@eliperelman eliperelman left a 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 edmorley force-pushed the edmorley-toConfig-validate-plugin branch from c3764b6 to d7b641f Compare July 20, 2020 15:41
@edmorley edmorley merged commit 7ad85cb into master Jul 20, 2020
@edmorley edmorley deleted the edmorley-toConfig-validate-plugin branch July 20, 2020 15:45
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.
Development

Successfully merging this pull request may close these issues.

2 participants