fix(tsc-wrapped): have UserError display the actual error

This commit is contained in:
Victor Berchet 2016-12-05 13:32:07 -08:00 committed by Alex Rickabaugh
parent 66b6fc010d
commit 393c1007a8
1 changed files with 13 additions and 4 deletions

View File

@ -25,12 +25,21 @@ export interface CompilerInterface {
} }
export class UserError extends Error { export class UserError extends Error {
private _nativeError: Error;
constructor(message: string) { constructor(message: string) {
super(message); // Errors don't use current this, instead they create a new instance.
this.message = message; // We have to do forward all of our api to the nativeInstance.
this.name = 'UserError'; const nativeError = super(message) as any as Error;
this.stack = new Error().stack; 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; const DEBUG = false;