diff --git a/src/cluster.ts b/src/cluster.ts index 51c8b07e..6a719a4f 100644 --- a/src/cluster.ts +++ b/src/cluster.ts @@ -6,6 +6,7 @@ import { RpcProvider } from 'worker-rpc'; import { NormalizedMessage } from './NormalizedMessage'; import { Message } from './Message'; import { RunPayload, RunResult, RUN } from './RpcTypes'; +import { prepareErrorForSerialization } from './util'; // fork workers... const division = parseInt(process.env.WORK_DIVISION || '', 10); @@ -51,7 +52,9 @@ parentRpc.registerRpcHandler(RUN, async message => { workerRpcs.map(workerRpc => workerRpc.rpc(RUN, message) ) - ); + ).catch(e => { + throw prepareErrorForSerialization(e); + }); function workerFinished( workerResult: (Message | undefined)[] diff --git a/src/index.ts b/src/index.ts index f6334e9f..e6a1cf0b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -412,7 +412,9 @@ class ForkTsCheckerWebpackPlugin { this.logger.error( this.colors.red( 'Error during checking: ' + - (error ? error.toString() : 'Unknown error') + (error + ? error.message || error.toString() + : 'Unknown error') ) ); } @@ -477,7 +479,9 @@ class ForkTsCheckerWebpackPlugin { this.logger.error( this.colors.red( 'Error during checking: ' + - (error ? error.toString() : 'Unknown error') + (error + ? error.message || error.toString() + : 'Unknown error') ) ); } diff --git a/src/service.ts b/src/service.ts index 90c47306..c1c7871f 100644 --- a/src/service.ts +++ b/src/service.ts @@ -12,6 +12,7 @@ import { } from './NormalizedMessageFactories'; import { RpcProvider } from 'worker-rpc'; import { RunPayload, RunResult, RUN } from './RpcTypes'; +import { prepareErrorForSerialization } from './util'; const rpc = new RpcProvider(message => { try { @@ -91,7 +92,9 @@ async function run(cancellationToken: CancellationToken) { rpc.registerRpcHandler(RUN, message => typeof message !== 'undefined' - ? run(CancellationToken.createFromJSON(typescript, message!)) + ? run(CancellationToken.createFromJSON(typescript, message!)).catch(e => { + throw prepareErrorForSerialization(e); + }) : undefined ); diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 00000000..ac952160 --- /dev/null +++ b/src/util.ts @@ -0,0 +1,23 @@ +export function prepareErrorForSerialization(e: any) { + const prepared = { + message: 'unkonwn error', + stack: 'no stack trace available', + fileName: 'unknown', + lineNumber: 'unknown', + columnNumber: 'unknown' + }; + + if (e) { + if (typeof e === 'string') { + prepared.message = e; + } else { + for (const key of Object.keys(prepared)) { + if (typeof e[key] !== 'undefined') { + prepared[key] = String(e[key]); + } + } + } + } + + return prepared; +}