Skip to content

Commit 20e78c1

Browse files
committed
fix: handle reporter errors
1 parent 695fc56 commit 20e78c1

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/plugin.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import webpack from 'webpack';
22
import env from 'std-env';
33

4+
import { consola } from './utils/cli';
5+
46
import { LogReporter, BarsReporter, ProfileReporter } from './reporters';
57
import Profile from './profile';
68
import { parseRequest } from './utils/request';
@@ -60,7 +62,11 @@ export default class WebpackBarPlugin extends webpack.ProgressPlugin {
6062
callReporters(fn, payload = {}) {
6163
for (const reporter of this.reporters) {
6264
if (typeof reporter[fn] === 'function') {
63-
reporter[fn](this, payload);
65+
try {
66+
reporter[fn](this, payload);
67+
} catch (e) {
68+
consola.error(e);
69+
}
6470
}
6571
}
6672
}

src/reporters/log.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import prettyTime from 'pretty-time';
2-
import Consola from 'consola';
32

4-
const consola = Consola.withTag('webpackbar');
3+
import { consola } from '../utils/cli';
54

65
export default class LogReporter {
76
compiling(context) {

src/utils/cli.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import chalk from 'chalk';
2+
import Consola from 'consola';
23

34
import textTable from 'text-table';
45

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

78
import { range } from '.';
89

10+
export const consola = Consola.withTag('webpackbar');
11+
912
export const colorize = (color) => {
1013
if (color[0] === '#') {
1114
return chalk.hex(color);

0 commit comments

Comments
 (0)