Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/scully-cmd-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The Scully CLI has the following options available:
- [ssl-key](#ssl-key)
- [highlight](#highlight)
- [tds](#tds)
- [pluginsError](#pluginsError)

## Serve

Expand Down Expand Up @@ -163,3 +164,12 @@ The following APIs are supported on the test data server:
- `/posts` - Returns a list of posts
- `/posts/:id` - Returns a post by id
- `/slow/:delay` - Returns 200 code after a delay has gone by. Eg: `/slow/2000` takes 2 seconds.

## pluginsError

```bash
npx scully --pluginsError=false
```

Show the error from the plugin, but continue rendering.
If you dont use the flag (by default is true) when you have an error into any plugin, the scully's run exit.
13 changes: 13 additions & 0 deletions plugins/demos/errorPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const {registerPlugin, logWarn} = require('../../dist/scully');

const errorPlugin = async (html, options) => {
try {
throw new Error(`new error`);
} catch (e) {
logWarn(`errorPlugin works!`);
}
return undefined;
};

const validator = async config => [];
registerPlugin('render', 'errorPlugin', errorPlugin, validator);
1 change: 1 addition & 0 deletions scully.sampleBlog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {getFlashPreventionPlugin} = require('./dist/scully-plugin-flash-preventio
require('./plugins/demos/extra-plugin.js');
require('./plugins/demos/tocPlugin');
require('./plugins/demos/voidPlugin');
require('./plugins/demos/errorPlugin');
const {setPluginConfig} = require('./dist/scully');

const FlashPrevention = getFlashPreventionPlugin();
Expand Down
9 changes: 9 additions & 0 deletions scully/renderPlugins/executePlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {plugins} from '../pluginManagement/pluginRepository';
import {HandledRoute} from '../routerPlugins/addOptionalRoutesPlugin';
import {logError, yellow} from '../utils/log';
import {puppeteerRender} from './puppeteerRenderPlugin';
import {pluginsError} from '../utils/cli-options';

export const executePluginsForRoute = async (route: HandledRoute) => {
/** make one array with all handlers for this route, filter out empty ones */
Expand Down Expand Up @@ -32,6 +33,14 @@ export const executePluginsForRoute = async (route: HandledRoute) => {
/** return result of plugin */
return await handler(html, route);
} catch {
if (pluginsError) {
logError(
`Error during content generation with plugin "${yellow(plugin)}" for ${yellow(
route.templateFile
)}.`
);
process.exit(15);
}
logError(
`Error during content generation with plugin "${yellow(plugin)}" for ${yellow(
route.templateFile
Expand Down
18 changes: 16 additions & 2 deletions scully/utils/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ export const {showBrowser, path, port, folder, sge} = yargs
.alias('sge', 'showGuessError')
.describe('sb', 'dumps the error from guess to the console').argv;

export const {configFileName, project, baseFilter, scanRoutes, pjFirst, hl, serverTimeout} = yargs
export const {
configFileName,
project,
baseFilter,
scanRoutes,
pjFirst,
hl,
serverTimeout,
pluginsError,
} = yargs
/** config file */
.string('cf')
.alias('cf', 'configFile')
Expand Down Expand Up @@ -115,7 +124,12 @@ export const {configFileName, project, baseFilter, scanRoutes, pjFirst, hl, serv
.string('hl')
.alias('hl', 'highlight')
.default('hl', false)
.describe('bf', 'provide a minimatch glob for the unhandled routes').argv;
.describe('hl', 'provide a minimatch glob for the unhandled routes')
/** Exit Scully with plugin error */
.boolean('pe')
.alias('pe', 'pluginsError')
.default('pe', true)
.describe('pe', "Exit scully's run when exist an error in a plugin").argv;

yargs.help();

Expand Down