From 393c1007a8694ad51d0e040041f51d72434358c8 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 5 Dec 2016 13:32:07 -0800 Subject: [PATCH] fix(tsc-wrapped): have UserError display the actual error --- tools/@angular/tsc-wrapped/src/tsc.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/@angular/tsc-wrapped/src/tsc.ts b/tools/@angular/tsc-wrapped/src/tsc.ts index 75a2844045..78039783f4 100644 --- a/tools/@angular/tsc-wrapped/src/tsc.ts +++ b/tools/@angular/tsc-wrapped/src/tsc.ts @@ -25,12 +25,21 @@ export interface CompilerInterface { } export class UserError extends Error { + private _nativeError: Error; + constructor(message: string) { - super(message); - this.message = message; - this.name = 'UserError'; - this.stack = new Error().stack; + // Errors don't use current this, instead they create a new instance. + // We have to do forward all of our api to the nativeInstance. + const nativeError = super(message) as any as Error; + this._nativeError = nativeError; } + + get message() { return this._nativeError.message; } + set message(message) { this._nativeError.message = message; } + get name() { return 'UserError'; } + get stack() { return (this._nativeError as any).stack; } + set stack(value) { (this._nativeError as any).stack = value; } + toString() { return this._nativeError.toString(); } } const DEBUG = false;