fix(errors): [2/2] Rename Exception to Error; remove from public API

BREAKING CHANGE:

Exceptions are no longer part of the public API. We don't expect that anyone should be referring to the Exception types.

ExceptionHandler.call(exception: any, stackTrace?: any, reason?: string): void;
change to:
ErrorHandler.handleError(error: any): void;
This commit is contained in:
Misko Hevery
2016-08-25 00:50:16 -07:00
committed by Victor Berchet
parent 86ba072758
commit 7c07bfff97
142 changed files with 565 additions and 774 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, unimplemented} from '../facade/exceptions';
import {unimplemented} from '../facade/errors';
import {stringify} from '../facade/lang';
const _THROW_IF_NOT_FOUND = new Object();
@ -15,7 +15,7 @@ export const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
class _NullInjector implements Injector {
get(token: any, notFoundValue: any = _THROW_IF_NOT_FOUND): any {
if (notFoundValue === _THROW_IF_NOT_FOUND) {
throw new BaseException(`No provider for ${stringify(token)}!`);
throw new Error(`No provider for ${stringify(token)}!`);
}
return notFoundValue;
}

View File

@ -7,9 +7,10 @@
*/
import {ListWrapper} from '../facade/collection';
import {BaseException, WrappedException} from '../facade/exceptions';
import {BaseError, WrappedError} from '../facade/errors';
import {isBlank, stringify} from '../facade/lang';
import {Type} from '../type';
import {ReflectiveInjector} from './reflective_injector';
import {ReflectiveKey} from './reflective_key';
@ -40,7 +41,7 @@ function constructResolvingPath(keys: any[]): string {
* Base class for all errors arising from misconfigured providers.
* @stable
*/
export class AbstractProviderError extends BaseException {
export class AbstractProviderError extends BaseError {
/** @internal */
message: string;
@ -55,7 +56,7 @@ export class AbstractProviderError extends BaseException {
constructor(
injector: ReflectiveInjector, key: ReflectiveKey, constructResolvingMessage: Function) {
super('DI Exception');
super('DI Error');
this.keys = [key];
this.injectors = [injector];
this.constructResolvingMessage = constructResolvingMessage;
@ -147,7 +148,7 @@ export class CyclicDependencyError extends AbstractProviderError {
* ```
* @stable
*/
export class InstantiationError extends WrappedException {
export class InstantiationError extends WrappedError {
/** @internal */
keys: ReflectiveKey[];
@ -157,7 +158,7 @@ export class InstantiationError extends WrappedException {
constructor(
injector: ReflectiveInjector, originalException: any, originalStack: any,
key: ReflectiveKey) {
super('DI Exception', originalException, originalStack, null);
super('DI Error', originalException);
this.keys = [key];
this.injectors = [injector];
}
@ -167,9 +168,9 @@ export class InstantiationError extends WrappedException {
this.keys.push(key);
}
get wrapperMessage(): string {
get message(): string {
var first = stringify(ListWrapper.first(this.keys).token);
return `Error during instantiation of ${first}!${constructResolvingPath(this.keys)}.`;
return `${this.originalError.message}: Error during instantiation of ${first}!${constructResolvingPath(this.keys)}.`;
}
get causeKey(): ReflectiveKey { return this.keys[0]; }
@ -188,7 +189,7 @@ export class InstantiationError extends WrappedException {
* ```
* @stable
*/
export class InvalidProviderError extends BaseException {
export class InvalidProviderError extends BaseError {
constructor(provider: any) {
super(`Invalid provider - only instances of Provider and Type are allowed, got: ${provider}`);
}
@ -223,7 +224,7 @@ export class InvalidProviderError extends BaseException {
* ```
* @stable
*/
export class NoAnnotationError extends BaseException {
export class NoAnnotationError extends BaseError {
constructor(typeOrFunc: Type<any>|Function, params: any[][]) {
super(NoAnnotationError._genMessage(typeOrFunc, params));
}
@ -259,7 +260,7 @@ export class NoAnnotationError extends BaseException {
* ```
* @stable
*/
export class OutOfBoundsError extends BaseException {
export class OutOfBoundsError extends BaseError {
constructor(index: number) { super(`Index ${index} is out-of-bounds.`); }
}
@ -276,7 +277,7 @@ export class OutOfBoundsError extends BaseException {
* ])).toThrowError();
* ```
*/
export class MixingMultiProvidersWithRegularProvidersError extends BaseException {
export class MixingMultiProvidersWithRegularProvidersError extends BaseError {
constructor(provider1: any, provider2: any) {
super(
'Cannot mix multi providers and regular providers, got: ' + provider1.toString() + ' ' +

View File

@ -7,13 +7,13 @@
*/
import {ListWrapper} from '../facade/collection';
import {BaseException, unimplemented} from '../facade/exceptions';
import {unimplemented} from '../facade/errors';
import {Type} from '../type';
import {Injector, THROW_IF_NOT_FOUND} from './injector';
import {SelfMetadata, SkipSelfMetadata} from './metadata';
import {Provider} from './provider';
import {AbstractProviderError, CyclicDependencyError, InstantiationError, NoProviderError, OutOfBoundsError} from './reflective_exceptions';
import {AbstractProviderError, CyclicDependencyError, InstantiationError, NoProviderError, OutOfBoundsError} from './reflective_errors';
import {ReflectiveKey} from './reflective_key';
import {ReflectiveDependency, ResolvedReflectiveFactory, ResolvedReflectiveProvider, resolveReflectiveProviders} from './reflective_provider';
@ -797,7 +797,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
d19);
break;
default:
throw new BaseException(
throw new Error(
`Cannot instantiate '${provider.key.displayName}' because it has more than 20 dependencies`);
}
} catch (e) {

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException} from '../facade/exceptions';
import {isBlank, stringify} from '../facade/lang';
import {resolveForwardRef} from './forward_ref';
@ -34,7 +33,7 @@ export class ReflectiveKey {
*/
constructor(public token: Object, public id: number) {
if (isBlank(token)) {
throw new BaseException('Token must be defined!');
throw new Error('Token must be defined!');
}
}

View File

@ -14,7 +14,7 @@ import {Type} from '../type';
import {resolveForwardRef} from './forward_ref';
import {DependencyMetadata, HostMetadata, InjectMetadata, OptionalMetadata, SelfMetadata, SkipSelfMetadata} from './metadata';
import {ClassProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ValueProvider} from './provider';
import {InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoAnnotationError} from './reflective_exceptions';
import {InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoAnnotationError} from './reflective_errors';
import {ReflectiveKey} from './reflective_key';