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:

committed by
Victor Berchet

parent
86ba072758
commit
7c07bfff97
@ -30,7 +30,7 @@ export {wtfCreateScope, wtfLeave, wtfStartTimeRange, wtfEndTimeRange, WtfScopeFn
|
||||
|
||||
export {Type} from './src/type';
|
||||
export {EventEmitter} from './src/facade/async';
|
||||
export {ExceptionHandler, WrappedException, BaseException} from './src/facade/exceptions';
|
||||
export {ErrorHandler} from './src/error_handler';
|
||||
export * from './private_export';
|
||||
|
||||
export * from './src/animation/metadata';
|
||||
|
@ -20,6 +20,7 @@ import * as console from './src/console';
|
||||
import * as debug from './src/debug/debug_renderer';
|
||||
import * as provider from './src/di/provider';
|
||||
import * as reflective_provider from './src/di/reflective_provider';
|
||||
import {ComponentStillLoadingError} from './src/linker/compiler';
|
||||
import * as component_factory_resolver from './src/linker/component_factory_resolver';
|
||||
import * as debug_context from './src/linker/debug_context';
|
||||
import * as element from './src/linker/element';
|
||||
@ -40,6 +41,7 @@ import * as api from './src/render/api';
|
||||
import * as security from './src/security';
|
||||
import * as decorators from './src/util/decorators';
|
||||
|
||||
|
||||
// These generic types can't be exported within the __core_private_types__
|
||||
// interface because the generic type info will be lost. So just exporting
|
||||
// them separately.
|
||||
@ -110,6 +112,7 @@ export interface __core_private_types__ {
|
||||
DEFAULT_STATE: typeof DEFAULT_STATE_;
|
||||
EMPTY_STATE: typeof EMPTY_STATE_;
|
||||
FILL_STYLE_FLAG: typeof FILL_STYLE_FLAG_;
|
||||
ComponentStillLoadingError: typeof ComponentStillLoadingError;
|
||||
}
|
||||
|
||||
export var __core_private__ = {
|
||||
@ -176,5 +179,6 @@ export var __core_private__ = {
|
||||
ANY_STATE: ANY_STATE_,
|
||||
DEFAULT_STATE: DEFAULT_STATE_,
|
||||
EMPTY_STATE: EMPTY_STATE_,
|
||||
FILL_STYLE_FLAG: FILL_STYLE_FLAG_
|
||||
FILL_STYLE_FLAG: FILL_STYLE_FLAG_,
|
||||
ComponentStillLoadingError: ComponentStillLoadingError
|
||||
};
|
||||
|
@ -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'); }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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';
|
||||
|
@ -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';
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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';
|
||||
|
@ -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)}`);
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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';
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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!');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,15 +8,13 @@
|
||||
|
||||
import {APP_BOOTSTRAP_LISTENER, APP_INITIALIZER, ChangeDetectorRef, CompilerFactory, Component, Injector, NgModule, PlatformRef, Type} from '@angular/core';
|
||||
import {ApplicationRef, ApplicationRef_} from '@angular/core/src/application_ref';
|
||||
import {Console} from '@angular/core/src/console';
|
||||
import {ErrorHandler} from '@angular/core/src/error_handler';
|
||||
import {ComponentRef} from '@angular/core/src/linker/component_factory';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
import {DOCUMENT} from '@angular/platform-browser/src/dom/dom_tokens';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {ExceptionHandler} from '../src/facade/exception_handler';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {TestBed, async, inject, withModule} from '../testing';
|
||||
|
||||
import {SpyChangeDetectorRef} from './spies';
|
||||
@ -27,14 +25,14 @@ class SomeComponent {
|
||||
|
||||
export function main() {
|
||||
describe('bootstrap', () => {
|
||||
var errorLogger: _ArrayLogger;
|
||||
var mockConsole: MockConsole;
|
||||
var fakeDoc: Document;
|
||||
|
||||
beforeEach(() => {
|
||||
fakeDoc = getDOM().createHtmlDocument();
|
||||
const el = getDOM().createElement('comp', fakeDoc);
|
||||
getDOM().appendChild(fakeDoc.body, el);
|
||||
errorLogger = new _ArrayLogger();
|
||||
mockConsole = new MockConsole();
|
||||
});
|
||||
|
||||
type CreateModuleOptions = {providers?: any[], ngDoBootstrap?: any, bootstrap?: any[]};
|
||||
@ -48,12 +46,13 @@ export function main() {
|
||||
} else {
|
||||
options = providersOrOptions || {};
|
||||
}
|
||||
const errorHandler = new ErrorHandler(false);
|
||||
errorHandler._console = mockConsole as any;
|
||||
|
||||
@NgModule({
|
||||
providers: [
|
||||
{provide: Console, useValue: new _MockConsole()},
|
||||
{provide: ExceptionHandler, useValue: new ExceptionHandler(errorLogger, false)},
|
||||
{provide: DOCUMENT, useValue: fakeDoc}, options.providers || []
|
||||
{provide: ErrorHandler, useValue: errorHandler}, {provide: DOCUMENT, useValue: fakeDoc},
|
||||
options.providers || []
|
||||
],
|
||||
imports: [BrowserModule],
|
||||
declarations: [SomeComponent],
|
||||
@ -153,7 +152,7 @@ export function main() {
|
||||
// we don't have an injector and therefore no way of
|
||||
// getting the exception handler. So
|
||||
// the error is only rethrown but not logged via the exception handler.
|
||||
expect(errorLogger.res).toEqual([]);
|
||||
expect(mockConsole.res).toEqual([]);
|
||||
});
|
||||
}));
|
||||
|
||||
@ -165,7 +164,7 @@ export function main() {
|
||||
]))
|
||||
.then(() => expect(false).toBe(true), (e) => {
|
||||
expect(e).toBe('Test');
|
||||
expect(errorLogger.res).toEqual(['EXCEPTION: Test']);
|
||||
expect(mockConsole.res).toEqual(['EXCEPTION: Test']);
|
||||
});
|
||||
}));
|
||||
|
||||
@ -206,7 +205,7 @@ export function main() {
|
||||
const expectedErrMsg =
|
||||
`The module MyModule was bootstrapped, but it does not declare "@NgModule.bootstrap" components nor a "ngDoBootstrap" method. Please define one of these.`;
|
||||
expect(e.message).toEqual(expectedErrMsg);
|
||||
expect(errorLogger.res).toEqual(['EXCEPTION: ' + expectedErrMsg]);
|
||||
expect(mockConsole.res[0]).toEqual('EXCEPTION: ' + expectedErrMsg);
|
||||
});
|
||||
}));
|
||||
});
|
||||
@ -243,7 +242,7 @@ export function main() {
|
||||
// we don't have an injector and therefore no way of
|
||||
// getting the exception handler. So
|
||||
// the error is only rethrown but not logged via the exception handler.
|
||||
expect(errorLogger.res).toEqual([]);
|
||||
expect(mockConsole.res).toEqual([]);
|
||||
}));
|
||||
|
||||
it('should rethrow promise errors even if the exceptionHandler is not rethrowing',
|
||||
@ -255,7 +254,7 @@ export function main() {
|
||||
defaultPlatform.bootstrapModuleFactory(moduleFactory)
|
||||
.then(() => expect(false).toBe(true), (e) => {
|
||||
expect(e).toBe('Test');
|
||||
expect(errorLogger.res).toEqual(['EXCEPTION: Test']);
|
||||
expect(mockConsole.res).toEqual(['EXCEPTION: Test']);
|
||||
});
|
||||
}));
|
||||
});
|
||||
@ -266,15 +265,8 @@ export function main() {
|
||||
class MyComp6 {
|
||||
}
|
||||
|
||||
class _ArrayLogger {
|
||||
class MockConsole {
|
||||
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(){};
|
||||
}
|
||||
|
||||
class _MockConsole implements Console {
|
||||
log(message: string) {}
|
||||
warn(message: string) {}
|
||||
error(s: any): void { this.res.push(s); }
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import {ReflectiveInjectorDynamicStrategy, ReflectiveInjectorInlineStrategy, Ref
|
||||
import {ResolvedReflectiveProvider_} from '@angular/core/src/di/reflective_provider';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {BaseException} from '../../src/facade/exceptions';
|
||||
import {isBlank, isPresent, stringify} from '../../src/facade/lang';
|
||||
|
||||
class CustomDependencyMetadata extends DependencyMetadata {}
|
||||
@ -20,7 +19,7 @@ class CustomDependencyMetadata extends DependencyMetadata {}
|
||||
class Engine {}
|
||||
|
||||
class BrokenEngine {
|
||||
constructor() { throw new BaseException('Broken Engine'); }
|
||||
constructor() { throw new Error('Broken Engine'); }
|
||||
}
|
||||
|
||||
class DashboardSoftware {}
|
||||
@ -332,7 +331,7 @@ export function main() {
|
||||
} catch (e) {
|
||||
expect(e.message).toContain(
|
||||
`Error during instantiation of Engine! (${stringify(Car)} -> Engine)`);
|
||||
expect(e.originalException instanceof BaseException).toBeTruthy();
|
||||
expect(e.originalError instanceof Error).toBeTruthy();
|
||||
expect(e.causeKey.token).toEqual(Engine);
|
||||
}
|
||||
});
|
||||
@ -364,7 +363,8 @@ export function main() {
|
||||
{provide: Engine, useFactory: (() => isBroken ? new BrokenEngine() : new Engine())}
|
||||
]);
|
||||
|
||||
expect(() => injector.get(Car)).toThrowError(new RegExp('Error'));
|
||||
expect(() => injector.get(Car))
|
||||
.toThrowError('Broken Engine: Error during instantiation of Engine! (Car -> Engine).');
|
||||
|
||||
isBroken = false;
|
||||
|
||||
|
@ -6,8 +6,16 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit,} from '@angular/core/testing/testing_internal';
|
||||
import {BaseException, WrappedException, ExceptionHandler} from '../src/exceptions';
|
||||
import {WrappedError} from '@angular/core/src/facade/errors';
|
||||
import {DebugContext} from '@angular/core/src/linker/debug_context';
|
||||
import {ViewWrappedError} from '@angular/core/src/linker/errors';
|
||||
|
||||
import {ErrorHandler} from '../src/error_handler';
|
||||
|
||||
class MockConsole {
|
||||
res: any[] = [];
|
||||
error(s: any): void { this.res.push(s); }
|
||||
}
|
||||
|
||||
class _CustomException {
|
||||
context = 'some context';
|
||||
@ -15,74 +23,78 @@ class _CustomException {
|
||||
}
|
||||
|
||||
export function main() {
|
||||
describe('ExceptionHandler', () => {
|
||||
function errorToString(error: any) {
|
||||
var logger = new MockConsole();
|
||||
var errorHandler = new ErrorHandler(false);
|
||||
errorHandler._console = logger as any;
|
||||
errorHandler.handleError(error);
|
||||
return logger.res.join('\n');
|
||||
}
|
||||
|
||||
function getStack(error: Error): string {
|
||||
try {
|
||||
throw error;
|
||||
} catch (e) {
|
||||
return e.stack;
|
||||
}
|
||||
}
|
||||
|
||||
describe('ErrorHandler', () => {
|
||||
it('should output exception', () => {
|
||||
var e = ExceptionHandler.exceptionToString(new BaseException('message!'));
|
||||
var e = errorToString(new Error('message!'));
|
||||
expect(e).toContain('message!');
|
||||
});
|
||||
|
||||
it('should output stackTrace', () => {
|
||||
var e = ExceptionHandler.exceptionToString(new BaseException('message!'), 'stack!');
|
||||
expect(e).toContain('stack!');
|
||||
});
|
||||
|
||||
it('should join a long stackTrace', () => {
|
||||
var e =
|
||||
ExceptionHandler.exceptionToString(new BaseException('message!'), ['stack1', 'stack2']);
|
||||
expect(e).toContain('stack1');
|
||||
expect(e).toContain('stack2');
|
||||
});
|
||||
|
||||
it('should output reason when present', () => {
|
||||
var e = ExceptionHandler.exceptionToString(new BaseException('message!'), null, 'reason!');
|
||||
expect(e).toContain('reason!');
|
||||
var error = new Error('message!');
|
||||
var stack = getStack(error);
|
||||
var e = errorToString(error);
|
||||
expect(e).toContain(stack);
|
||||
});
|
||||
|
||||
describe('context', () => {
|
||||
it('should print context', () => {
|
||||
var e = ExceptionHandler.exceptionToString(
|
||||
new WrappedException('message!', null, null, 'context!'));
|
||||
expect(e).toContain('context!');
|
||||
});
|
||||
|
||||
it('should print nested context', () => {
|
||||
var original = new WrappedException('message!', null, null, 'context!');
|
||||
var e = ExceptionHandler.exceptionToString(new WrappedException('message', original));
|
||||
expect(e).toContain('context!');
|
||||
});
|
||||
|
||||
it('should not print context when the passed-in exception is not a BaseException', () => {
|
||||
var e = ExceptionHandler.exceptionToString(new _CustomException());
|
||||
expect(e).not.toContain('context');
|
||||
var cause = new Error('message!');
|
||||
var stack = getStack(cause);
|
||||
var context = {
|
||||
source: 'context!',
|
||||
toString() { return 'Context'; }
|
||||
} as any as DebugContext;
|
||||
var original = new ViewWrappedError(cause, context);
|
||||
var e = errorToString(new WrappedError('message', original));
|
||||
expect(e).toEqual(`EXCEPTION: message caused by: Error in context! caused by: message!
|
||||
ORIGINAL EXCEPTION: message!
|
||||
ORIGINAL STACKTRACE:
|
||||
${stack}
|
||||
ERROR CONTEXT:
|
||||
Context`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('original exception', () => {
|
||||
it('should print original exception message if available (original is BaseException)', () => {
|
||||
var realOriginal = new BaseException('inner');
|
||||
var original = new WrappedException('wrapped', realOriginal);
|
||||
var e =
|
||||
ExceptionHandler.exceptionToString(new WrappedException('wrappedwrapped', original));
|
||||
expect(e).toContain('inner');
|
||||
it('should print original exception message if available (original is Error)', () => {
|
||||
var realOriginal = new Error('inner');
|
||||
var stack = getStack(realOriginal);
|
||||
var original = new WrappedError('wrapped', realOriginal);
|
||||
var e = errorToString(new WrappedError('wrappedwrapped', original));
|
||||
expect(e).toContain(stack);
|
||||
});
|
||||
|
||||
it('should print original exception message if available (original is not BaseException)',
|
||||
() => {
|
||||
var realOriginal = new _CustomException();
|
||||
var original = new WrappedException('wrapped', realOriginal);
|
||||
var e =
|
||||
ExceptionHandler.exceptionToString(new WrappedException('wrappedwrapped', original));
|
||||
expect(e).toContain('custom');
|
||||
});
|
||||
it('should print original exception message if available (original is not Error)', () => {
|
||||
var realOriginal = new _CustomException();
|
||||
var original = new WrappedError('wrapped', realOriginal);
|
||||
var e = errorToString(new WrappedError('wrappedwrapped', original));
|
||||
expect(e).toContain('custom');
|
||||
});
|
||||
});
|
||||
|
||||
describe('original stack', () => {
|
||||
it('should print original stack if available', () => {
|
||||
var realOriginal = new BaseException('inner');
|
||||
var original = new WrappedException('wrapped', realOriginal, 'originalStack');
|
||||
var e = ExceptionHandler.exceptionToString(
|
||||
new WrappedException('wrappedwrapped', original, 'wrappedStack'));
|
||||
expect(e).toContain('originalStack');
|
||||
var realOriginal = new Error('inner');
|
||||
var stack = getStack(realOriginal);
|
||||
var original = new WrappedError('wrapped', realOriginal);
|
||||
var e = errorToString(new WrappedError('wrappedwrapped', original));
|
||||
expect(e).toContain(stack);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,7 +6,6 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {BaseException} from '@angular/core';
|
||||
import {discardPeriodicTasks, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {Log, beforeEach, ddescribe, describe, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
@ -93,16 +92,14 @@ export function main() {
|
||||
it('should complain if the test throws an exception during async calls', () => {
|
||||
expect(() => {
|
||||
fakeAsync(() => {
|
||||
resolvedPromise.then((_) => { throw new BaseException('async'); });
|
||||
resolvedPromise.then((_) => { throw new Error('async'); });
|
||||
flushMicrotasks();
|
||||
})();
|
||||
}).toThrowError('Uncaught (in promise): async');
|
||||
}).toThrowError('Uncaught (in promise): Error: async');
|
||||
});
|
||||
|
||||
it('should complain if a test throws an exception', () => {
|
||||
expect(() => {
|
||||
fakeAsync(() => { throw new BaseException('sync'); })();
|
||||
}).toThrowError('sync');
|
||||
expect(() => { fakeAsync(() => { throw new Error('sync'); })(); }).toThrowError('sync');
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -18,7 +18,6 @@ import {DomRootRenderer} from '@angular/platform-browser/src/dom/dom_renderer';
|
||||
|
||||
import {EventEmitter} from '../../src/facade/async';
|
||||
import {StringMapWrapper} from '../../src/facade/collection';
|
||||
import {BaseException} from '../../src/facade/exceptions';
|
||||
import {NumberWrapper, isBlank} from '../../src/facade/lang';
|
||||
|
||||
export function main() {
|
||||
@ -724,7 +723,7 @@ export function main() {
|
||||
try {
|
||||
ctx.detectChanges(false);
|
||||
} catch (e) {
|
||||
throw new BaseException('Second detectChanges() should not have run detection.');
|
||||
throw new Error('Second detectChanges() should not have run detection.');
|
||||
}
|
||||
expect(directiveLog.filter(['ngOnInit'])).toEqual([]);
|
||||
}));
|
||||
@ -821,7 +820,7 @@ export function main() {
|
||||
try {
|
||||
ctx.detectChanges(false);
|
||||
} catch (e) {
|
||||
throw new BaseException('Second detectChanges() should not have run detection.');
|
||||
throw new Error('Second detectChanges() should not have run detection.');
|
||||
}
|
||||
expect(directiveLog.filter(['ngAfterContentInit'])).toEqual([]);
|
||||
}));
|
||||
@ -935,7 +934,7 @@ export function main() {
|
||||
try {
|
||||
ctx.detectChanges(false);
|
||||
} catch (e) {
|
||||
throw new BaseException('Second detectChanges() should not have run detection.');
|
||||
throw new Error('Second detectChanges() should not have run detection.');
|
||||
}
|
||||
expect(directiveLog.filter(['ngAfterViewInit'])).toEqual([]);
|
||||
}));
|
||||
@ -1342,7 +1341,7 @@ class TestDirective implements OnInit, DoCheck, OnChanges, AfterContentInit, Aft
|
||||
ngOnInit() {
|
||||
this.log.add(this.name, 'ngOnInit');
|
||||
if (this.throwOn == 'ngOnInit') {
|
||||
throw new BaseException('Boom!');
|
||||
throw new Error('Boom!');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1352,42 +1351,42 @@ class TestDirective implements OnInit, DoCheck, OnChanges, AfterContentInit, Aft
|
||||
StringMapWrapper.forEach(changes, (c: SimpleChange, key: string) => r[key] = c.currentValue);
|
||||
this.changes = r;
|
||||
if (this.throwOn == 'ngOnChanges') {
|
||||
throw new BaseException('Boom!');
|
||||
throw new Error('Boom!');
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterContentInit() {
|
||||
this.log.add(this.name, 'ngAfterContentInit');
|
||||
if (this.throwOn == 'ngAfterContentInit') {
|
||||
throw new BaseException('Boom!');
|
||||
throw new Error('Boom!');
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterContentChecked() {
|
||||
this.log.add(this.name, 'ngAfterContentChecked');
|
||||
if (this.throwOn == 'ngAfterContentChecked') {
|
||||
throw new BaseException('Boom!');
|
||||
throw new Error('Boom!');
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.log.add(this.name, 'ngAfterViewInit');
|
||||
if (this.throwOn == 'ngAfterViewInit') {
|
||||
throw new BaseException('Boom!');
|
||||
throw new Error('Boom!');
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewChecked() {
|
||||
this.log.add(this.name, 'ngAfterViewChecked');
|
||||
if (this.throwOn == 'ngAfterViewChecked') {
|
||||
throw new BaseException('Boom!');
|
||||
throw new Error('Boom!');
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.log.add(this.name, 'ngOnDestroy');
|
||||
if (this.throwOn == 'ngOnDestroy') {
|
||||
throw new BaseException('Boom!');
|
||||
throw new Error('Boom!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,10 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, NoComponentFactoryError, forwardRef} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, forwardRef} from '@angular/core';
|
||||
import {NoComponentFactoryError} from '@angular/core/src/linker/component_factory_resolver';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
|
||||
import {Console} from '../../src/console';
|
||||
|
||||
|
||||
|
@ -23,7 +23,6 @@ import {dispatchEvent, el} from '@angular/platform-browser/testing/browser_util'
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {EventEmitter} from '../../src/facade/async';
|
||||
import {BaseException} from '../../src/facade/exceptions';
|
||||
import {isBlank, isPresent, stringify} from '../../src/facade/lang';
|
||||
|
||||
const ANCHOR_ELEMENT = new OpaqueToken('AnchorElement');
|
||||
@ -2091,7 +2090,7 @@ class OtherDuplicateDir {
|
||||
|
||||
@Directive({selector: 'directive-throwing-error'})
|
||||
class DirectiveThrowingAnError {
|
||||
constructor() { throw new BaseException('BOOM'); }
|
||||
constructor() { throw new Error('BOOM'); }
|
||||
}
|
||||
|
||||
@Component({
|
||||
|
@ -11,14 +11,13 @@ import {Console} from '@angular/core/src/console';
|
||||
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {BaseException} from '../../src/facade/exceptions';
|
||||
import {stringify} from '../../src/facade/lang';
|
||||
import {NgModuleInjector} from '../../src/linker/ng_module_factory';
|
||||
|
||||
class Engine {}
|
||||
|
||||
class BrokenEngine {
|
||||
constructor() { throw new BaseException('Broken Engine'); }
|
||||
constructor() { throw new Error('Broken Engine'); }
|
||||
}
|
||||
|
||||
class DashboardSoftware {}
|
||||
|
@ -6,12 +6,11 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {BaseException} from '@angular/core';
|
||||
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||
import {async, fakeAsync, flushMicrotasks} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, Log, beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||
import {browserDetection} from '@angular/platform-browser/testing/browser_util';
|
||||
|
||||
import {BaseError} from '../../src/facade/errors';
|
||||
import {isPresent, scheduleMicroTask} from '../../src/facade/lang';
|
||||
|
||||
var needsLongerTimers = browserDetection.isSlow || browserDetection.isEdge;
|
||||
@ -95,7 +94,7 @@ export function main() {
|
||||
setTimeout(() => {
|
||||
setTimeout(() => {
|
||||
resolve(null);
|
||||
throw new BaseException('ccc');
|
||||
throw new BaseError('ccc');
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
@ -118,7 +117,7 @@ export function main() {
|
||||
scheduleMicroTask(() => {
|
||||
scheduleMicroTask(() => {
|
||||
resolve(null);
|
||||
throw new BaseException('ddd');
|
||||
throw new BaseError('ddd');
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -153,7 +152,7 @@ export function main() {
|
||||
setTimeout(() => {
|
||||
setTimeout(() => {
|
||||
resolve(null);
|
||||
throw new BaseException('ccc');
|
||||
throw new BaseError('ccc');
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
@ -720,7 +719,7 @@ function commonTests() {
|
||||
it('should call the on error callback when it is invoked via zone.runGuarded',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
macroTask(() => {
|
||||
var exception = new BaseException('sync');
|
||||
var exception = new BaseError('sync');
|
||||
|
||||
_zone.runGuarded(() => { throw exception; });
|
||||
|
||||
@ -733,7 +732,7 @@ function commonTests() {
|
||||
it('should not call the on error callback but rethrow when it is invoked via zone.run',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
macroTask(() => {
|
||||
var exception = new BaseException('sync');
|
||||
var exception = new BaseError('sync');
|
||||
expect(() => _zone.run(() => { throw exception; })).toThrowError('sync');
|
||||
|
||||
expect(_errors.length).toBe(0);
|
||||
@ -743,7 +742,7 @@ function commonTests() {
|
||||
|
||||
it('should call onError for errors from microtasks',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var exception = new BaseException('async');
|
||||
var exception = new BaseError('async');
|
||||
|
||||
macroTask(() => { _zone.run(() => { scheduleMicroTask(() => { throw exception; }); }); });
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
import {ChangeDetectorRef, ComponentRef, DebugElement, ElementRef, NgZone, getDebugNode} from '../index';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {scheduleMicroTask} from '../src/facade/lang';
|
||||
|
||||
import {tick} from './fake_async';
|
||||
@ -146,7 +145,7 @@ export class ComponentFixture<T> {
|
||||
*/
|
||||
autoDetectChanges(autoDetect: boolean = true) {
|
||||
if (this.ngZone == null) {
|
||||
throw new BaseException('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set');
|
||||
throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set');
|
||||
}
|
||||
this._autoDetect = autoDetect;
|
||||
this.detectChanges();
|
||||
|
@ -6,7 +6,6 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {BaseException} from '../index';
|
||||
|
||||
|
||||
const FakeAsyncTestZoneSpec = (Zone as any)['FakeAsyncTestZoneSpec'];
|
||||
@ -53,13 +52,13 @@ export function fakeAsync(fn: Function): (...args: any[]) => any {
|
||||
return function(...args: any[]) {
|
||||
const proxyZoneSpec = ProxyZoneSpec.assertPresent();
|
||||
if (_inFakeAsyncCall) {
|
||||
throw new BaseException('fakeAsync() calls can not be nested');
|
||||
throw new Error('fakeAsync() calls can not be nested');
|
||||
}
|
||||
_inFakeAsyncCall = true;
|
||||
try {
|
||||
if (!_fakeAsyncTestZoneSpec) {
|
||||
if (proxyZoneSpec.getDelegate() instanceof FakeAsyncTestZoneSpec) {
|
||||
throw new BaseException('fakeAsync() calls can not be nested');
|
||||
throw new Error('fakeAsync() calls can not be nested');
|
||||
}
|
||||
|
||||
_fakeAsyncTestZoneSpec = new FakeAsyncTestZoneSpec();
|
||||
@ -76,13 +75,13 @@ export function fakeAsync(fn: Function): (...args: any[]) => any {
|
||||
}
|
||||
|
||||
if (_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length > 0) {
|
||||
throw new BaseException(
|
||||
throw new Error(
|
||||
`${_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length} ` +
|
||||
`periodic timer(s) still in the queue.`);
|
||||
}
|
||||
|
||||
if (_fakeAsyncTestZoneSpec.pendingTimers.length > 0) {
|
||||
throw new BaseException(
|
||||
throw new Error(
|
||||
`${_fakeAsyncTestZoneSpec.pendingTimers.length} timer(s) still in the queue.`);
|
||||
}
|
||||
return res;
|
||||
|
@ -6,9 +6,8 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {CompilerOptions, ComponentMetadataType, ComponentStillLoadingError, DirectiveMetadataType, Injector, ModuleWithComponentFactories, NgModule, NgModuleFactory, NgModuleMetadataType, NgModuleRef, NgZone, OpaqueToken, PipeMetadataType, PlatformRef, Provider, SchemaMetadata} from '../index';
|
||||
import {CompilerOptions, ComponentMetadataType, DirectiveMetadataType, Injector, ModuleWithComponentFactories, NgModule, NgModuleFactory, NgModuleMetadataType, NgModuleRef, NgZone, OpaqueToken, PipeMetadataType, PlatformRef, Provider, SchemaMetadata} from '../index';
|
||||
import {ListWrapper} from '../src/facade/collection';
|
||||
import {BaseException} from '../src/facade/exceptions';
|
||||
import {FunctionWrapper, stringify} from '../src/facade/lang';
|
||||
import {Type} from '../src/type';
|
||||
|
||||
@ -173,7 +172,7 @@ export class TestBed implements Injector {
|
||||
*/
|
||||
initTestEnvironment(ngModule: Type<any>, platform: PlatformRef) {
|
||||
if (this.platform || this.ngModule) {
|
||||
throw new BaseException('Cannot set base providers because it has already been called');
|
||||
throw new Error('Cannot set base providers because it has already been called');
|
||||
}
|
||||
this.platform = platform;
|
||||
this.ngModule = ngModule;
|
||||
@ -256,7 +255,7 @@ export class TestBed implements Injector {
|
||||
this._moduleWithComponentFactories =
|
||||
this._compiler.compileModuleAndAllComponentsSync(moduleType);
|
||||
} catch (e) {
|
||||
if (e instanceof ComponentStillLoadingError) {
|
||||
if (e.compType) {
|
||||
throw new Error(
|
||||
`This test module uses the component ${stringify(e.compType)} which is using a "templateUrl", but they were never compiled. ` +
|
||||
`Please call "TestBed.compileComponents" before your test.`);
|
||||
@ -296,7 +295,7 @@ export class TestBed implements Injector {
|
||||
|
||||
private _assertNotInstantiated(methodName: string, methodDescription: string) {
|
||||
if (this._instantiated) {
|
||||
throw new BaseException(
|
||||
throw new Error(
|
||||
`Cannot ${methodDescription} when the test module has already been instantiated. ` +
|
||||
`Make sure you are not using \`inject\` before \`${methodName}\`.`);
|
||||
}
|
||||
@ -344,7 +343,7 @@ export class TestBed implements Injector {
|
||||
const componentFactory = this._moduleWithComponentFactories.componentFactories.find(
|
||||
(compFactory) => compFactory.componentType === component);
|
||||
if (!componentFactory) {
|
||||
throw new BaseException(
|
||||
throw new Error(
|
||||
`Cannot create the component ${stringify(component)} as it was not imported into the testing module!`);
|
||||
}
|
||||
const noNgZone = this.get(ComponentFixtureNoNgZone, false);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {Compiler, CompilerOptions, ComponentMetadataType, DirectiveMetadataType, Injector, NgModuleMetadataType, PipeMetadataType} from '../index';
|
||||
import {unimplemented} from '../src/facade/exceptions';
|
||||
import {unimplemented} from '../src/facade/errors';
|
||||
import {Type} from '../src/type';
|
||||
import {MetadataOverride} from './metadata_override';
|
||||
|
||||
|
Reference in New Issue
Block a user