From 5a095bb257598c1cb4c31003b96d78b297a54d7e Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Fri, 17 Apr 2015 19:18:29 +0200 Subject: [PATCH] refactor(di): rename ProviderError to BindingError Closes #1428 --- modules/angular2/di.js | 2 +- modules/angular2/docs/di/di.md | 4 ++-- modules/angular2/src/core/compiler/element_injector.js | 5 +++-- modules/angular2/src/di/exceptions.js | 10 +++++----- modules/angular2/src/di/injector.js | 8 ++++---- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/modules/angular2/di.js b/modules/angular2/di.js index cae9dc506d..63a7eea84d 100644 --- a/modules/angular2/di.js +++ b/modules/angular2/di.js @@ -9,6 +9,6 @@ export {Inject, InjectPromise, InjectLazy, Injectable, Optional, DependencyAnnot export {Injector} from './src/di/injector'; export {Binding, ResolvedBinding, Dependency, bind} from './src/di/binding'; export {Key, KeyRegistry} from './src/di/key'; -export {KeyMetadataError, NoProviderError, ProviderError, AsyncBindingError, CyclicDependencyError, +export {KeyMetadataError, NoBindingError, AbstractBindingError, AsyncBindingError, CyclicDependencyError, InstantiationError, InvalidBindingError, NoAnnotationError} from './src/di/exceptions'; export {OpaqueToken} from './src/di/opaque_token'; diff --git a/modules/angular2/docs/di/di.md b/modules/angular2/docs/di/di.md index a049bf8350..0a32ad5761 100644 --- a/modules/angular2/docs/di/di.md +++ b/modules/angular2/docs/di/di.md @@ -316,8 +316,8 @@ ctrlPromise.then((ctrl) { expect(ctrl).toBeAnInstanceOf(UserController); expect(ctrl.ul).toBeAnInstanceOf(UserList); }); -// No synchronous provider for UserList, results in a NoProviderError. -expect(() => inj.get(UserController)).toThrow(new NoProviderError(...)); +// No synchronous provider for UserList, results in a NoBindingError. +expect(() => inj.get(UserController)).toThrow(new NoBindingError(...)); ``` diff --git a/modules/angular2/src/core/compiler/element_injector.js b/modules/angular2/src/core/compiler/element_injector.js index 36d63204b6..921b819990 100644 --- a/modules/angular2/src/core/compiler/element_injector.js +++ b/modules/angular2/src/core/compiler/element_injector.js @@ -1,7 +1,8 @@ import {isPresent, isBlank, Type, int, BaseException} from 'angular2/src/facade/lang'; import {Math} from 'angular2/src/facade/math'; import {List, ListWrapper, MapWrapper} from 'angular2/src/facade/collection'; -import {Injector, Key, Dependency, bind, Binding, ResolvedBinding, NoProviderError, ProviderError, CyclicDependencyError} from 'angular2/di'; +import {Injector, Key, Dependency, bind, Binding, ResolvedBinding, NoBindingError, + AbstractBindingError, CyclicDependencyError} from 'angular2/di'; import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility'; import {PropertySetter, Attribute, Query} from 'angular2/src/core/annotations/di'; import * as viewModule from 'angular2/src/core/compiler/view'; @@ -702,7 +703,7 @@ export class ElementInjector extends TreeNode { d8 = length > 8 ? this._getByDependency(deps[8], binding.key) : null; d9 = length > 9 ? this._getByDependency(deps[9], binding.key) : null; } catch(e) { - if (e instanceof ProviderError) e.addKey(binding.key); + if (e instanceof AbstractBindingError) e.addKey(binding.key); throw e; } diff --git a/modules/angular2/src/di/exceptions.js b/modules/angular2/src/di/exceptions.js index 9fcca70966..17f7e222d2 100644 --- a/modules/angular2/src/di/exceptions.js +++ b/modules/angular2/src/di/exceptions.js @@ -30,7 +30,7 @@ function constructResolvingPath(keys:List) { * * @exportedAs angular2/di_errors */ -export class ProviderError extends Error { +export class AbstractBindingError extends Error { keys:List; constructResolvingMessage:Function; message; @@ -59,7 +59,7 @@ export class ProviderError extends Error { * * @exportedAs angular2/di_errors */ -export class NoProviderError extends ProviderError { +export class NoBindingError extends AbstractBindingError { // TODO(tbosch): Can't do key:Key as this results in a circular dependency! constructor(key) { super(key, function (keys:List) { @@ -93,7 +93,7 @@ export class NoProviderError extends ProviderError { * * @exportedAs angular2/di_errors */ -export class AsyncBindingError extends ProviderError { +export class AsyncBindingError extends AbstractBindingError { // TODO(tbosch): Can't do key:Key as this results in a circular dependency! constructor(key) { super(key, function (keys:List) { @@ -122,7 +122,7 @@ export class AsyncBindingError extends ProviderError { * * @exportedAs angular2/di_errors */ -export class CyclicDependencyError extends ProviderError { +export class CyclicDependencyError extends AbstractBindingError { // TODO(tbosch): Can't do key:Key as this results in a circular dependency! constructor(key) { super(key, function (keys:List) { @@ -139,7 +139,7 @@ export class CyclicDependencyError extends ProviderError { * * @exportedAs angular2/di_errors */ -export class InstantiationError extends ProviderError { +export class InstantiationError extends AbstractBindingError { // TODO(tbosch): Can't do key:Key as this results in a circular dependency! constructor(originalException, key) { super(key, function (keys:List) { diff --git a/modules/angular2/src/di/injector.js b/modules/angular2/src/di/injector.js index acd42a0b79..ba9d54501c 100644 --- a/modules/angular2/src/di/injector.js +++ b/modules/angular2/src/di/injector.js @@ -1,6 +1,6 @@ import {Map, List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection'; import {ResolvedBinding, Binding, BindingBuilder, bind} from './binding'; -import {ProviderError, NoProviderError, AsyncBindingError, CyclicDependencyError, +import {AbstractBindingError, NoBindingError, AsyncBindingError, CyclicDependencyError, InstantiationError, InvalidBindingError} from './exceptions'; import {FunctionWrapper, Type, isPresent, isBlank} from 'angular2/src/facade/lang'; import {Promise, PromiseWrapper} from 'angular2/src/facade/async'; @@ -205,7 +205,7 @@ export class Injector { if (optional) { return null; } else { - throw new NoProviderError(key); + throw new NoBindingError(key); } } @@ -215,7 +215,7 @@ export class Injector { return ListWrapper.map(binding.dependencies, getDependency); } catch (e) { this._clear(key); - if (e instanceof ProviderError) e.addKey(key); + if (e instanceof AbstractBindingError) e.addKey(key); throw e; } } @@ -343,7 +343,7 @@ class _AsyncInjectorStrategy { } _errorHandler(key:Key, e):Promise { - if (e instanceof ProviderError) e.addKey(key); + if (e instanceof AbstractBindingError) e.addKey(key); return PromiseWrapper.reject(e); }