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

@ -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`);
}
/**

View File

@ -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';

View File

@ -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)}`);
}

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();

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}`); }
}

View File

@ -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;

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;
}
};

View File

@ -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';

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';
/**

View File

@ -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 {