Skip to content

Commit

Permalink
fix: handle reporter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 1, 2018
1 parent 695fc56 commit 20e78c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import webpack from 'webpack';
import env from 'std-env';

import { consola } from './utils/cli';

import { LogReporter, BarsReporter, ProfileReporter } from './reporters';
import Profile from './profile';
import { parseRequest } from './utils/request';
Expand Down Expand Up @@ -60,7 +62,11 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
callReporters(fn, payload = {}) {
for (const reporter of this.reporters) {
if (typeof reporter[fn] === 'function') {
reporter[fn](this, payload);
try {
reporter[fn](this, payload);
} catch (e) {
consola.error(e);
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/reporters/log.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import prettyTime from 'pretty-time';
import Consola from 'consola';

const consola = Consola.withTag('webpackbar');
import { consola } from '../utils/cli';

export default class LogReporter {
compiling(context) {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/cli.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import chalk from 'chalk';
import Consola from 'consola';

import textTable from 'text-table';

import { BLOCK_CHAR, BLOCK_CHAR2, BAR_LENGTH } from './consts';

import { range } from '.';

export const consola = Consola.withTag('webpackbar');

export const colorize = (color) => {
if (color[0] === '#') {
return chalk.hex(color);
Expand Down

0 comments on commit 20e78c1

Please sign in to comment.