From eaa20f661ad28366fa3fe3c0b0f6413d6ef7792e Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 16 Sep 2015 17:47:10 -0700 Subject: [PATCH] fix(exceptions): NoAnnotationError message is not displayed Closes #4215 Closes #4223 --- modules/angular2/src/core/di/exceptions.ts | 40 +++++-------------- .../angular2/src/core/facade/exceptions.ts | 2 +- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/modules/angular2/src/core/di/exceptions.ts b/modules/angular2/src/core/di/exceptions.ts index b4cf1e1c80..a88154992c 100644 --- a/modules/angular2/src/core/di/exceptions.ts +++ b/modules/angular2/src/core/di/exceptions.ts @@ -32,7 +32,6 @@ function constructResolvingPath(keys: any[]): string { * Base class for all errors arising from misconfigured bindings. */ export class AbstractBindingError extends BaseException { - name: string; message: string; keys: Key[]; injectors: Injector[]; @@ -99,7 +98,6 @@ export class CyclicDependencyError extends AbstractBindingError { * this object to be instantiated. */ export class InstantiationError extends WrappedException { - name: string; keys: Key[]; injectors: Injector[]; @@ -129,14 +127,10 @@ export class InstantiationError extends WrappedException { * creation. */ export class InvalidBindingError extends BaseException { - message: string; constructor(binding) { - super(); - this.message = "Invalid binding - only instances of Binding and Type are allowed, got: " + - binding.toString(); + super("Invalid binding - only instances of Binding and Type are allowed, got: " + + binding.toString()); } - - toString(): string { return this.message; } } /** @@ -146,10 +140,11 @@ export class InvalidBindingError extends BaseException { * need to be injected into the constructor. */ export class NoAnnotationError extends BaseException { - name: string; - message: string; constructor(typeOrFunc, params: any[][]) { - super(); + super(NoAnnotationError._genMessage(typeOrFunc, params)); + } + + private static _genMessage(typeOrFunc, params: any[][]) { var signature = []; for (var i = 0, ii = params.length; i < ii; i++) { var parameter = params[i]; @@ -159,37 +154,24 @@ export class NoAnnotationError extends BaseException { signature.push(ListWrapper.map(parameter, stringify).join(' ')); } } - this.message = "Cannot resolve all parameters for " + stringify(typeOrFunc) + "(" + - signature.join(', ') + "). " + - 'Make sure they all have valid type or annotations.'; + return "Cannot resolve all parameters for " + stringify(typeOrFunc) + "(" + + signature.join(', ') + "). " + 'Make sure they all have valid type or annotations.'; } - - toString(): string { return this.message; } } /** * Thrown when getting an object by index. */ export class OutOfBoundsError extends BaseException { - message: string; - constructor(index) { - super(); - this.message = `Index ${index} is out-of-bounds.`; - } - - toString(): string { return this.message; } + constructor(index) { super(`Index ${index} is out-of-bounds.`); } } /** * Thrown when a multi binding and a regular binding are bound to the same token. */ export class MixingMultiBindingsWithRegularBindings extends BaseException { - message: string; constructor(binding1, binding2) { - super(); - this.message = "Cannot mix multi bindings and regular bindings, got: " + binding1.toString() + - " " + binding2.toString(); + super("Cannot mix multi bindings and regular bindings, got: " + binding1.toString() + " " + + binding2.toString()); } - - toString(): string { return this.message; } } \ No newline at end of file diff --git a/modules/angular2/src/core/facade/exceptions.ts b/modules/angular2/src/core/facade/exceptions.ts index a84ba2f858..9dbf2d7aa2 100644 --- a/modules/angular2/src/core/facade/exceptions.ts +++ b/modules/angular2/src/core/facade/exceptions.ts @@ -6,7 +6,7 @@ export {ExceptionHandler} from './exception_handler'; export class BaseException extends Error { public stack: any; - constructor(public message?: string) { + constructor(public message: string = "--") { super(message); this.stack = (new Error(message)).stack; }