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
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException} from '../facade/exceptions';
import {scheduleMicroTask} from '../facade/lang';
@@ -26,10 +25,8 @@ export abstract class AnimationPlayer {
abstract reset(): void;
abstract setPosition(p: any /** TODO #9100 */): void;
abstract getPosition(): number;
get parentPlayer(): AnimationPlayer { throw new BaseException('NOT IMPLEMENTED: Base Class'); }
set parentPlayer(player: AnimationPlayer) {
throw new BaseException('NOT IMPLEMENTED: Base Class');
}
get parentPlayer(): AnimationPlayer { throw new Error('NOT IMPLEMENTED: Base Class'); }
set parentPlayer(player: AnimationPlayer) { throw new Error('NOT IMPLEMENTED: Base Class'); }
}
export class NoOpAnimationPlayer implements AnimationPlayer {
@@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException} from '../facade/exceptions';
import {NumberWrapper, isArray, isPresent, isString} from '../facade/lang';
/**
@@ -102,7 +101,7 @@ export class AnimationAnimateMetadata extends AnimationMetadata {
*/
export abstract class AnimationWithStepsMetadata extends AnimationMetadata {
constructor() { super(); }
get steps(): AnimationMetadata[] { throw new BaseException('NOT IMPLEMENTED: Base Class'); }
get steps(): AnimationMetadata[] { throw new Error('NOT IMPLEMENTED: Base Class'); }
}
/**
+16 -18
View File
@@ -6,8 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ErrorHandler} from '../src/error_handler';
import {ListWrapper} from '../src/facade/collection';
import {BaseException, ExceptionHandler, unimplemented} from '../src/facade/exceptions';
import {unimplemented} from '../src/facade/errors';
import {isBlank, isPresent, isPromise, stringify} from '../src/facade/lang';
import {ApplicationInitStatus} from './application_init';
@@ -40,8 +41,7 @@ var _platform: PlatformRef;
*/
export function enableProdMode(): void {
if (_runModeLocked) {
// Cannot use BaseException as that ends up importing from facade/lang.
throw new BaseException('Cannot enable prod mode after platform setup.');
throw new Error('Cannot enable prod mode after platform setup.');
}
_devMode = false;
}
@@ -67,7 +67,7 @@ export function isDevMode(): boolean {
*/
export function createPlatform(injector: Injector): PlatformRef {
if (isPresent(_platform) && !_platform.destroyed) {
throw new BaseException(
throw new Error(
'There can be only one platform. Destroy the previous one to create a new one.');
}
_platform = injector.get(PlatformRef);
@@ -115,10 +115,10 @@ export function createPlatformFactory(
export function assertPlatform(requiredToken: any): PlatformRef {
var platform = getPlatform();
if (isBlank(platform)) {
throw new BaseException('No platform exists!');
throw new Error('No platform exists!');
}
if (isPresent(platform) && isBlank(platform.injector.get(requiredToken, null))) {
throw new BaseException(
throw new Error(
'A platform with a different configuration has been created. Please destroy it first.');
}
return platform;
@@ -221,13 +221,12 @@ export abstract class PlatformRef {
get destroyed(): boolean { throw unimplemented(); }
}
function _callAndReportToExceptionHandler(
exceptionHandler: ExceptionHandler, callback: () => any): any {
function _callAndReportToExceptionHandler(errorHandler: ErrorHandler, callback: () => any): any {
try {
const result = callback();
if (isPromise(result)) {
return result.catch((e: any) => {
exceptionHandler.call(e);
errorHandler.handleError(e);
// rethrow as the exception handler might not do it
throw e;
});
@@ -235,7 +234,7 @@ function _callAndReportToExceptionHandler(
return result;
}
} catch (e) {
exceptionHandler.call(e);
errorHandler.handleError(e);
// rethrow as the exception handler might not do it
throw e;
}
@@ -258,7 +257,7 @@ export class PlatformRef_ extends PlatformRef {
destroy() {
if (this._destroyed) {
throw new BaseException('The platform has already been destroyed!');
throw new Error('The platform has already been destroyed!');
}
ListWrapper.clone(this._modules).forEach((app) => app.destroy());
this._destroyListeners.forEach((dispose) => dispose());
@@ -282,13 +281,12 @@ export class PlatformRef_ extends PlatformRef {
const ngZoneInjector =
ReflectiveInjector.resolveAndCreate([{provide: NgZone, useValue: ngZone}], this.injector);
const moduleRef = <NgModuleInjector<M>>moduleFactory.create(ngZoneInjector);
const exceptionHandler: ExceptionHandler = moduleRef.injector.get(ExceptionHandler, null);
const exceptionHandler: ErrorHandler = moduleRef.injector.get(ErrorHandler, null);
if (!exceptionHandler) {
throw new Error('No ExceptionHandler. Is platform module (BrowserModule) included?');
}
moduleRef.onDestroy(() => ListWrapper.remove(this._modules, moduleRef));
ngZone.onError.subscribe(
{next: (error: any) => { exceptionHandler.call(error, error ? error.stack : null); }});
ngZone.onError.subscribe({next: (error: any) => { exceptionHandler.handleError(error); }});
return _callAndReportToExceptionHandler(exceptionHandler, () => {
const initStatus: ApplicationInitStatus = moduleRef.injector.get(ApplicationInitStatus);
return initStatus.donePromise.then(() => {
@@ -333,7 +331,7 @@ export class PlatformRef_ extends PlatformRef {
} else if (moduleRef.instance.ngDoBootstrap) {
moduleRef.instance.ngDoBootstrap(appRef);
} else {
throw new BaseException(
throw new Error(
`The module ${stringify(moduleRef.instance.constructor)} was bootstrapped, but it does not declare "@NgModule.bootstrap" components nor a "ngDoBootstrap" method. ` +
`Please define one of these.`);
}
@@ -400,7 +398,7 @@ export class ApplicationRef_ extends ApplicationRef {
constructor(
private _zone: NgZone, private _console: Console, private _injector: Injector,
private _exceptionHandler: ExceptionHandler,
private _exceptionHandler: ErrorHandler,
private _componentFactoryResolver: ComponentFactoryResolver,
private _initStatus: ApplicationInitStatus,
@Optional() private _testabilityRegistry: TestabilityRegistry,
@@ -422,7 +420,7 @@ export class ApplicationRef_ extends ApplicationRef {
bootstrap<C>(componentOrFactory: ComponentFactory<C>|Type<C>): ComponentRef<C> {
if (!this._initStatus.done) {
throw new BaseException(
throw new Error(
'Cannot bootstrap as there are still asynchronous initializers running. Bootstrap components in the `ngDoBootstrap` method of the root module.');
}
let componentFactory: ComponentFactory<C>;
@@ -471,7 +469,7 @@ export class ApplicationRef_ extends ApplicationRef {
tick(): void {
if (this._runningTick) {
throw new BaseException('ApplicationRef.tick is called recursively');
throw new Error('ApplicationRef.tick is called recursively');
}
var s = ApplicationRef_._tickScope();
@@ -7,7 +7,6 @@
*/
import {isListLikeIterable, iterateListLike} from '../../facade/collection';
import {BaseException} from '../../facade/exceptions';
import {getMapKey, isArray, isBlank, isPresent, looseIdentical, stringify} from '../../facade/lang';
import {ChangeDetectorRef} from '../change_detector_ref';
@@ -150,7 +149,7 @@ export class DefaultIterableDiffer implements IterableDiffer {
diff(collection: any): DefaultIterableDiffer {
if (isBlank(collection)) collection = [];
if (!isListLikeIterable(collection)) {
throw new BaseException(`Error trying to diff '${collection}'`);
throw new Error(`Error trying to diff '${collection}'`);
}
if (this.check(collection)) {
@@ -7,7 +7,6 @@
*/
import {StringMapWrapper} from '../../facade/collection';
import {BaseException} from '../../facade/exceptions';
import {isJsObject, looseIdentical, stringify} from '../../facade/lang';
import {ChangeDetectorRef} from '../change_detector_ref';
@@ -76,7 +75,7 @@ export class DefaultKeyValueDiffer implements KeyValueDiffer {
if (!map) {
map = new Map();
} else if (!(map instanceof Map || isJsObject(map))) {
throw new BaseException(`Error trying to diff '${map}'`);
throw new Error(`Error trying to diff '${map}'`);
}
return this.check(map) ? this : null;
@@ -8,7 +8,6 @@
import {OptionalMetadata, Provider, SkipSelfMetadata} from '../../di';
import {ListWrapper} from '../../facade/collection';
import {BaseException} from '../../facade/exceptions';
import {getTypeNameForDebugging, isBlank, isPresent} from '../../facade/lang';
import {ChangeDetectorRef} from '../change_detector_ref';
@@ -87,7 +86,7 @@ export class IterableDiffers {
// Typically would occur when calling IterableDiffers.extend inside of dependencies passed
// to
// bootstrap(), which would override default pipes instead of extending them.
throw new BaseException('Cannot extend IterableDiffers without a parent injector');
throw new Error('Cannot extend IterableDiffers without a parent injector');
}
return IterableDiffers.create(factories, parent);
},
@@ -101,7 +100,7 @@ export class IterableDiffers {
if (isPresent(factory)) {
return factory;
} else {
throw new BaseException(
throw new Error(
`Cannot find a differ supporting object '${iterable}' of type '${getTypeNameForDebugging(iterable)}'`);
}
}
@@ -8,7 +8,6 @@
import {OptionalMetadata, Provider, SkipSelfMetadata} from '../../di';
import {ListWrapper} from '../../facade/collection';
import {BaseException} from '../../facade/exceptions';
import {isBlank, isPresent} from '../../facade/lang';
import {ChangeDetectorRef} from '../change_detector_ref';
@@ -77,7 +76,7 @@ export class KeyValueDiffers {
// Typically would occur when calling KeyValueDiffers.extend inside of dependencies passed
// to
// bootstrap(), which would override default pipes instead of extending them.
throw new BaseException('Cannot extend KeyValueDiffers without a parent injector');
throw new Error('Cannot extend KeyValueDiffers without a parent injector');
}
return KeyValueDiffers.create(factories, parent);
},
@@ -91,7 +90,7 @@ export class KeyValueDiffers {
if (isPresent(factory)) {
return factory;
} else {
throw new BaseException(`Cannot find a differ supporting object '${kv}'`);
throw new Error(`Cannot find a differ supporting object '${kv}'`);
}
}
}
-1
View File
@@ -25,5 +25,4 @@ export {ReflectiveInjector} from './di/reflective_injector';
export {Provider, TypeProvider, ValueProvider, ClassProvider, ExistingProvider, FactoryProvider} from './di/provider';
export {ResolvedReflectiveFactory, ResolvedReflectiveProvider} from './di/reflective_provider';
export {ReflectiveKey} from './di/reflective_key';
export {NoProviderError, AbstractProviderError, CyclicDependencyError, InstantiationError, InvalidProviderError, NoAnnotationError, OutOfBoundsError} from './di/reflective_exceptions';
export {OpaqueToken} from './di/opaque_token';
+2 -2
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;
}
@@ -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() + ' ' +
@@ -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) {
@@ -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!');
}
}
@@ -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';
+44 -78
View File
@@ -6,22 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseWrappedException} from './base_wrapped_exception';
import {isListLikeIterable} from './collection';
import {isBlank, isPresent} from './lang';
class _ArrayLogger {
res: any[] = [];
log(s: any): void { this.res.push(s); }
logError(s: any): void { this.res.push(s); }
logGroup(s: any): void { this.res.push(s); }
logGroupEnd(){};
}
import {WrappedError} from './facade/errors';
/**
* Provides a hook for centralized exception handling.
*
* The default implementation of `ExceptionHandler` prints error messages to the `Console`. To
* The default implementation of `ErrorHandler` prints error messages to the `Console`. To
* intercept error handling,
* write a custom exception handler that replaces this default as appropriate for your app.
*
@@ -29,112 +19,88 @@ class _ArrayLogger {
*
* ```javascript
*
* class MyExceptionHandler implements ExceptionHandler {
* class MyExceptionHandler implements ErrorHandler {
* call(error, stackTrace = null, reason = null) {
* // do something with the exception
* }
* }
*
* @NgModule({
* providers: [{provide: ExceptionHandler, useClass: MyExceptionHandler}]
* providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
* })
* class MyModule {}
* ```
* @stable
*/
export class ExceptionHandler {
constructor(private _logger: any, private _rethrowException: boolean = true) {}
export class ErrorHandler {
/**
* @internal
*/
_console: Console = console;
static exceptionToString(exception: any, stackTrace: any = null, reason: string = null): string {
var l = new _ArrayLogger();
var e = new ExceptionHandler(l, false);
e.call(exception, stackTrace, reason);
return l.res.join('\n');
}
constructor(private rethrowError: boolean = true) {}
call(exception: any, stackTrace: any = null, reason: string = null): void {
var originalException = this._findOriginalException(exception);
var originalStack = this._findOriginalStack(exception);
var context = this._findContext(exception);
handleError(error: any): void {
var originalError = this._findOriginalError(error);
var originalStack = this._findOriginalStack(error);
var context = this._findContext(error);
this._logger.logGroup(`EXCEPTION: ${this._extractMessage(exception)}`);
this._console.error(`EXCEPTION: ${this._extractMessage(error)}`);
if (isPresent(stackTrace) && isBlank(originalStack)) {
this._logger.logError('STACKTRACE:');
this._logger.logError(this._longStackTrace(stackTrace));
if (originalError) {
this._console.error(`ORIGINAL EXCEPTION: ${this._extractMessage(originalError)}`);
}
if (isPresent(reason)) {
this._logger.logError(`REASON: ${reason}`);
if (originalStack) {
this._console.error('ORIGINAL STACKTRACE:');
this._console.error(originalStack);
}
if (isPresent(originalException)) {
this._logger.logError(`ORIGINAL EXCEPTION: ${this._extractMessage(originalException)}`);
if (context) {
this._console.error('ERROR CONTEXT:');
this._console.error(context);
}
if (isPresent(originalStack)) {
this._logger.logError('ORIGINAL STACKTRACE:');
this._logger.logError(this._longStackTrace(originalStack));
}
if (isPresent(context)) {
this._logger.logError('ERROR CONTEXT:');
this._logger.logError(context);
}
this._logger.logGroupEnd();
// We rethrow exceptions, so operations like 'bootstrap' will result in an error
// when an exception happens. If we do not rethrow, bootstrap will always succeed.
if (this._rethrowException) throw exception;
// when an error happens. If we do not rethrow, bootstrap will always succeed.
if (this.rethrowError) throw error;
}
/** @internal */
_extractMessage(exception: any): string {
return exception instanceof BaseWrappedException ? exception.wrapperMessage :
exception.toString();
_extractMessage(error: any): string {
return error instanceof Error ? error.message : error.toString();
}
/** @internal */
_longStackTrace(stackTrace: any): any {
return isListLikeIterable(stackTrace) ? (<any[]>stackTrace).join('\n\n-----async gap-----\n') :
stackTrace.toString();
}
/** @internal */
_findContext(exception: any): any {
try {
if (!(exception instanceof BaseWrappedException)) return null;
return isPresent(exception.context) ? exception.context :
this._findContext(exception.originalException);
} catch (e) {
// exception.context can throw an exception. if it happens, we ignore the context.
_findContext(error: any): any {
if (error) {
return error.context ? error.context :
this._findContext((error as WrappedError).originalError);
} else {
return null;
}
}
/** @internal */
_findOriginalException(exception: any): any {
if (!(exception instanceof BaseWrappedException)) return null;
var e = exception.originalException;
while (e instanceof BaseWrappedException && isPresent(e.originalException)) {
e = e.originalException;
_findOriginalError(error: any): any {
var e = (error as WrappedError).originalError;
while (e && (e as WrappedError).originalError) {
e = (e as WrappedError).originalError;
}
return e;
}
/** @internal */
_findOriginalStack(exception: any): any {
if (!(exception instanceof BaseWrappedException)) return null;
_findOriginalStack(error: any): string {
if (!(error instanceof Error)) return null;
var e = exception;
var stack = exception.originalStack;
while (e instanceof BaseWrappedException && isPresent(e.originalException)) {
e = e.originalException;
if (e instanceof BaseWrappedException && isPresent(e.originalException)) {
stack = e.originalStack;
var e: any = error;
var stack: string = e.stack;
while (e instanceof Error && (e as WrappedError).originalError) {
e = (e as WrappedError).originalError;
if (e instanceof Error && e.stack) {
stack = e.stack;
}
}
+2 -3
View File
@@ -7,11 +7,10 @@
*/
// Public API for compiler
export {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, ComponentStillLoadingError, ModuleWithComponentFactories} from './linker/compiler';
export {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, ModuleWithComponentFactories} from './linker/compiler';
export {ComponentFactory, ComponentRef} from './linker/component_factory';
export {ComponentFactoryResolver, NoComponentFactoryError} from './linker/component_factory_resolver';
export {ComponentFactoryResolver} from './linker/component_factory_resolver';
export {ElementRef} from './linker/element_ref';
export {ExpressionChangedAfterItHasBeenCheckedException} from './linker/exceptions';
export {NgModuleFactory, NgModuleRef} from './linker/ng_module_factory';
export {NgModuleFactoryLoader} from './linker/ng_module_factory_loader';
export {QueryList} from './linker/query_list';
+3 -3
View File
@@ -7,7 +7,7 @@
*/
import {OpaqueToken} from '../di';
import {BaseException} from '../facade/exceptions';
import {BaseError} from '../facade/errors';
import {stringify} from '../facade/lang';
import {ViewEncapsulation} from '../metadata';
import {Type} from '../type';
@@ -22,7 +22,7 @@ import {NgModuleFactory} from './ng_module_factory';
*
* @stable
*/
export class ComponentStillLoadingError extends BaseException {
export class ComponentStillLoadingError extends BaseError {
constructor(public compType: Type<any>) {
super(`Can't compile synchronously as ${stringify(compType)} is still being loaded!`);
}
@@ -41,7 +41,7 @@ export class ModuleWithComponentFactories<T> {
function _throwError() {
throw new BaseException(`Runtime compiler is not loaded`);
throw new Error(`Runtime compiler is not loaded`);
}
/**
@@ -8,7 +8,7 @@
import {ChangeDetectorRef} from '../change_detection/change_detection';
import {Injector} from '../di/injector';
import {unimplemented} from '../facade/exceptions';
import {unimplemented} from '../facade/errors';
import {isBlank} from '../facade/lang';
import {Type} from '../type';
import {AppElement} from './element';
@@ -6,17 +6,18 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException} from '../facade/exceptions';
import {BaseError} from '../facade/errors';
import {stringify} from '../facade/lang';
import {Type} from '../type';
import {ComponentFactory} from './component_factory';
/**
* @stable
*/
export class NoComponentFactoryError extends BaseException {
export class NoComponentFactoryError extends BaseError {
constructor(public component: Function) {
super(`No component factory found for ${stringify(component)}`);
}
+3 -4
View File
@@ -8,7 +8,6 @@
import {Injector} from '../di/injector';
import {ListWrapper} from '../facade/collection';
import {BaseException} from '../facade/exceptions';
import {isPresent} from '../facade/lang';
import {ElementRef} from './element_ref';
@@ -63,7 +62,7 @@ export class AppElement {
moveView(view: AppView<any>, currentIndex: number) {
var previousIndex = this.nestedViews.indexOf(view);
if (view.type === ViewType.COMPONENT) {
throw new BaseException(`Component views can't be moved!`);
throw new Error(`Component views can't be moved!`);
}
var nestedViews = this.nestedViews;
if (nestedViews == null) {
@@ -87,7 +86,7 @@ export class AppElement {
attachView(view: AppView<any>, viewIndex: number) {
if (view.type === ViewType.COMPONENT) {
throw new BaseException(`Component views can't be moved!`);
throw new Error(`Component views can't be moved!`);
}
var nestedViews = this.nestedViews;
if (nestedViews == null) {
@@ -111,7 +110,7 @@ export class AppElement {
detachView(viewIndex: number): AppView<any> {
var view = ListWrapper.removeAt(this.nestedViews, viewIndex);
if (view.type === ViewType.COMPONENT) {
throw new BaseException(`Component views can't be moved!`);
throw new Error(`Component views can't be moved!`);
}
view.detach();
+17 -8
View File
@@ -7,7 +7,10 @@
*/
import {UNINITIALIZED} from '../change_detection/change_detection_util';
import {BaseException, WrappedException} from '../facade/exceptions';
import {BaseError, WrappedError} from '../facade/errors';
import {DebugContext} from './debug_context';
/**
@@ -37,15 +40,15 @@ import {BaseException, WrappedException} from '../facade/exceptions';
*
* set prop(v) {
* // this updates the parent property, which is disallowed during change detection
* // this will result in ExpressionChangedAfterItHasBeenCheckedException
* // this will result in ExpressionChangedAfterItHasBeenCheckedError
* this.parent.parentProp = "updated";
* }
* }
* ```
* @stable
*/
export class ExpressionChangedAfterItHasBeenCheckedException extends BaseException {
constructor(oldValue: any, currValue: any, context: any) {
export class ExpressionChangedAfterItHasBeenCheckedError extends BaseError {
constructor(oldValue: any, currValue: any) {
let msg =
`Expression has changed after it was checked. Previous value: '${oldValue}'. Current value: '${currValue}'.`;
if (oldValue === UNINITIALIZED) {
@@ -64,9 +67,15 @@ export class ExpressionChangedAfterItHasBeenCheckedException extends BaseExcepti
* be useful for debugging.
* @stable
*/
export class ViewWrappedException extends WrappedException {
constructor(originalException: any, originalStack: any, context: any) {
super(`Error in ${context.source}`, originalException, originalStack, context);
export class ViewWrappedError extends WrappedError {
/**
* DebugContext
*/
context: DebugContext;
constructor(originalError: any, context: DebugContext) {
super(`Error in ${context.source}`, originalError);
this.context = context;
}
}
@@ -78,6 +87,6 @@ export class ViewWrappedException extends WrappedException {
* This is an internal Angular error.
* @stable
*/
export class ViewDestroyedException extends BaseException {
export class ViewDestroyedError extends BaseError {
constructor(details: string) { super(`Attempt to use a destroyed view: ${details}`); }
}
@@ -7,7 +7,7 @@
*/
import {Injector, THROW_IF_NOT_FOUND} from '../di/injector';
import {BaseException, unimplemented} from '../facade/exceptions';
import {unimplemented} from '../facade/errors';
import {stringify} from '../facade/lang';
import {Type} from '../type';
import {ComponentFactory} from './component_factory';
@@ -107,7 +107,7 @@ export abstract class NgModuleInjector<T> extends CodegenComponentFactoryResolve
destroy(): void {
if (this._destroyed) {
throw new BaseException(
throw new Error(
`The ng module ${stringify(this.instance.constructor)} has already been destroyed.`);
}
this._destroyed = true;
+12 -12
View File
@@ -21,7 +21,7 @@ import {RenderComponentType, RenderDebugInfo, Renderer} from '../render/api';
import {DebugContext, StaticNodeDebugInfo} from './debug_context';
import {AppElement} from './element';
import {ElementInjector} from './element_injector';
import {ExpressionChangedAfterItHasBeenCheckedException, ViewDestroyedException, ViewWrappedException} from './exceptions';
import {ExpressionChangedAfterItHasBeenCheckedError, ViewDestroyedError, ViewWrappedError} from './errors';
import {ViewRef_} from './view_ref';
import {ViewType} from './view_type';
import {ViewUtils, ensureSlotCount, flattenNestedViewRenderNodes} from './view_utils';
@@ -357,7 +357,7 @@ export abstract class AppView<T> {
eventHandler(cb: Function): Function { return cb; }
throwDestroyedError(details: string): void { throw new ViewDestroyedException(details); }
throwDestroyedError(details: string): void { throw new ViewDestroyedError(details); }
}
export class DebugAppView<T> extends AppView<T> {
@@ -376,7 +376,7 @@ export class DebugAppView<T> extends AppView<T> {
try {
return super.create(context, givenProjectableNodes, rootSelectorOrNode);
} catch (e) {
this._rethrowWithContext(e, e.stack);
this._rethrowWithContext(e);
throw e;
}
}
@@ -386,7 +386,7 @@ export class DebugAppView<T> extends AppView<T> {
try {
return super.injectorGet(token, nodeIndex, notFoundResult);
} catch (e) {
this._rethrowWithContext(e, e.stack);
this._rethrowWithContext(e);
throw e;
}
}
@@ -396,7 +396,7 @@ export class DebugAppView<T> extends AppView<T> {
try {
super.detach();
} catch (e) {
this._rethrowWithContext(e, e.stack);
this._rethrowWithContext(e);
throw e;
}
}
@@ -406,7 +406,7 @@ export class DebugAppView<T> extends AppView<T> {
try {
super.destroyLocal();
} catch (e) {
this._rethrowWithContext(e, e.stack);
this._rethrowWithContext(e);
throw e;
}
}
@@ -416,7 +416,7 @@ export class DebugAppView<T> extends AppView<T> {
try {
super.detectChanges(throwOnChange);
} catch (e) {
this._rethrowWithContext(e, e.stack);
this._rethrowWithContext(e);
throw e;
}
}
@@ -427,13 +427,13 @@ export class DebugAppView<T> extends AppView<T> {
return this._currentDebugContext = new DebugContext(this, nodeIndex, rowNum, colNum);
}
private _rethrowWithContext(e: any, stack: any) {
if (!(e instanceof ViewWrappedException)) {
if (!(e instanceof ExpressionChangedAfterItHasBeenCheckedException)) {
private _rethrowWithContext(e: any) {
if (!(e instanceof ViewWrappedError)) {
if (!(e instanceof ExpressionChangedAfterItHasBeenCheckedError)) {
this.cdMode = ChangeDetectorStatus.Errored;
}
if (isPresent(this._currentDebugContext)) {
throw new ViewWrappedException(e, stack, this._currentDebugContext);
throw new ViewWrappedError(e, this._currentDebugContext);
}
}
}
@@ -445,7 +445,7 @@ export class DebugAppView<T> extends AppView<T> {
try {
return superHandler(event);
} catch (e) {
this._rethrowWithContext(e, e.stack);
this._rethrowWithContext(e);
throw e;
}
};
@@ -8,7 +8,7 @@
import {Injector} from '../di/injector';
import {ListWrapper} from '../facade/collection';
import {unimplemented} from '../facade/exceptions';
import {unimplemented} from '../facade/errors';
import {isPresent} from '../facade/lang';
import {WtfScopeFn, wtfCreateScope, wtfLeave} from '../profile/profile';
import {ComponentFactory, ComponentRef} from './component_factory';
+1 -1
View File
@@ -8,7 +8,7 @@
import {ChangeDetectorRef} from '../change_detection/change_detector_ref';
import {ChangeDetectorStatus} from '../change_detection/constants';
import {unimplemented} from '../facade/exceptions';
import {unimplemented} from '../facade/errors';
import {AppView} from './view';
/**
@@ -11,13 +11,12 @@ import {devModeEqual} from '../change_detection/change_detection';
import {UNINITIALIZED} from '../change_detection/change_detection_util';
import {Inject, Injectable} from '../di/decorators';
import {ListWrapper} from '../facade/collection';
import {BaseException} from '../facade/exceptions';
import {isBlank, isPresent, looseIdentical} from '../facade/lang';
import {ViewEncapsulation} from '../metadata/view';
import {RenderComponentType, Renderer, RootRenderer} from '../render/api';
import {Sanitizer} from '../security';
import {AppElement} from './element';
import {ExpressionChangedAfterItHasBeenCheckedException} from './exceptions';
import {ExpressionChangedAfterItHasBeenCheckedError} from './errors';
@Injectable()
export class ViewUtils {
@@ -124,7 +123,7 @@ export function interpolate(
c3 + _toStringWithNull(a4) + c4 + _toStringWithNull(a5) + c5 + _toStringWithNull(a6) +
c6 + _toStringWithNull(a7) + c7 + _toStringWithNull(a8) + c8 + _toStringWithNull(a9) + c9;
default:
throw new BaseException(`Does not support more than 9 expressions`);
throw new Error(`Does not support more than 9 expressions`);
}
}
@@ -135,7 +134,7 @@ function _toStringWithNull(v: any): string {
export function checkBinding(throwOnChange: boolean, oldValue: any, newValue: any): boolean {
if (throwOnChange) {
if (!devModeEqual(oldValue, newValue)) {
throw new ExpressionChangedAfterItHasBeenCheckedException(oldValue, newValue, null);
throw new ExpressionChangedAfterItHasBeenCheckedError(oldValue, newValue);
}
return false;
} else {
@@ -7,7 +7,6 @@
*/
import {Map, MapWrapper, Set, SetWrapper, StringMapWrapper} from '../facade/collection';
import {BaseException} from '../facade/exceptions';
import {isPresent} from '../facade/lang';
import {Type} from '../type';
import {PlatformReflectionCapabilities} from './platform_reflection_capabilities';
@@ -67,7 +66,7 @@ export class Reflector extends ReflectorReader {
*/
listUnusedKeys(): any[] {
if (this._usedKeys == null) {
throw new BaseException('Usage tracking is disabled');
throw new Error('Usage tracking is disabled');
}
var allTypes = MapWrapper.keys(this._injectableInfo);
return allTypes.filter(key => !SetWrapper.has(this._usedKeys, key));
+1 -1
View File
@@ -10,7 +10,7 @@ import {AnimationKeyframe} from '../../src/animation/animation_keyframe';
import {AnimationPlayer} from '../../src/animation/animation_player';
import {AnimationStyles} from '../../src/animation/animation_styles';
import {Injector} from '../di/injector';
import {unimplemented} from '../facade/exceptions';
import {unimplemented} from '../facade/errors';
import {ViewEncapsulation} from '../metadata/view';
/**
@@ -8,7 +8,6 @@
import {Injectable} from '../di/decorators';
import {Map, MapWrapper} from '../facade/collection';
import {BaseException} from '../facade/exceptions';
import {scheduleMicroTask} from '../facade/lang';
import {NgZone} from '../zone/ng_zone';
@@ -68,7 +67,7 @@ export class Testability {
decreasePendingRequestCount(): number {
this._pendingCount -= 1;
if (this._pendingCount < 0) {
throw new BaseException('pending async requests below zero');
throw new Error('pending async requests below zero');
}
this._runCallbacksIfReady();
return this._pendingCount;
+2 -3
View File
@@ -7,7 +7,6 @@
*/
import {EventEmitter} from '../facade/async';
import {BaseException} from '../facade/exceptions';
import {NgZoneImpl} from './ng_zone_impl';
@@ -88,12 +87,12 @@ export class NgZone {
static isInAngularZone(): boolean { return NgZoneImpl.isInAngularZone(); }
static assertInAngularZone(): void {
if (!NgZoneImpl.isInAngularZone()) {
throw new BaseException('Expected to be in Angular Zone, but it is not!');
throw new Error('Expected to be in Angular Zone, but it is not!');
}
}
static assertNotInAngularZone(): void {
if (NgZoneImpl.isInAngularZone()) {
throw new BaseException('Expected to not be in Angular Zone, but it is!');
throw new Error('Expected to not be in Angular Zone, but it is!');
}
}