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

Improve error message when .tap() used on an undefined plugin #271

Merged
merged 1 commit into from
Jul 20, 2020

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented 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 by a later preset, IMO that ordering was already broken, since the .tap()'s args would have been overwritten by the subsequent preset.

Fixes #125.

@edmorley edmorley self-assigned this Jul 19, 2020
@edmorley edmorley requested a review from a team July 19, 2020 18:29
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 force-pushed the edmorley-validate-tap-plugin branch from e4692ca to 1fb2f6d Compare July 20, 2020 15:47
@edmorley edmorley merged commit 38ef3c4 into master Jul 20, 2020
@edmorley edmorley deleted the edmorley-validate-tap-plugin branch July 20, 2020 15:53
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.

Improve error message when using .tap() on undefined plugin
2 participants