Skip to content

Commit

Permalink
fix(registerplugin): better error on type (#225)
Browse files Browse the repository at this point in the history
* fix(registerplugin): better error on type

When given the wrong type for a plugin, throw a proper explaination.

closes #219

* fix(typo): fix typo in errormessage
  • Loading branch information
SanderElias authored Jan 23, 2020
1 parent 6ee2b01 commit 99c0253
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions scully/pluginManagement/pluginRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ export const registerPlugin = (
{replaceExistingPlugin = false} = {}
) => {
if (!['router', 'render', 'fileHandler'].includes(type)) {
throw new Error(
`Type "${yellow(type)}" is not a known plugin type for registering plugin "${yellow(name)}"`
);
throw new Error(`
--------------
Type "${yellow(type)}" is not a known plugin type for registering plugin "${yellow(name)}".
The first parameter of registerPlugin needs to be one of: 'fileHandler', 'router', 'render'
--------------
`);
}
if (replaceExistingPlugin === false && plugins[type][name]) {
throw new Error(`Plugin ${name} already exists`);
Expand Down
1 change: 1 addition & 0 deletions scully/pluginManagement/systemPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import '../fileHanderPlugins/asciidoc';
import '../renderPlugins/contentRenderPlugin';
import '../routerPlugins/jsonRoutePlugin';
import '../routerPlugins/contentFolderPlugin';
import '../routerPlugins/ignoredRoutePlugin';
7 changes: 7 additions & 0 deletions scully/routerPlugins/ignoredRoutePlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {registerPlugin} from '../pluginManagement/pluginRepository';

/**
* The ignoredPlugin helps to take routes out.
* when you use this plugin, the route will never be rendered.
*/
registerPlugin('router', 'ignored', () => []);

0 comments on commit 99c0253

Please sign in to comment.