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 {CommonModule, PlatformLocation} from '@angular/common';
import {ApplicationModule, BaseException, ClassProvider, ExceptionHandler, ExistingProvider, FactoryProvider, NgModule, Optional, PLATFORM_INITIALIZER, PlatformRef, Provider, RootRenderer, Sanitizer, SkipSelf, Testability, TypeProvider, ValueProvider, createPlatformFactory, platformCore} from '@angular/core';
import {ApplicationModule, ClassProvider, ErrorHandler, ExistingProvider, FactoryProvider, NgModule, Optional, PLATFORM_INITIALIZER, PlatformRef, Provider, RootRenderer, Sanitizer, SkipSelf, Testability, TypeProvider, ValueProvider, createPlatformFactory, platformCore} from '@angular/core';
import {wtfInit} from '../core_private';
import {AnimationDriver} from '../src/dom/animation_driver';
@ -55,8 +55,8 @@ export function initDomAdapter() {
BrowserGetTestability.init();
}
export function _exceptionHandler(): ExceptionHandler {
return new ExceptionHandler(getDOM());
export function errorHandler(): ErrorHandler {
return new ErrorHandler();
}
export function _document(): any {
@ -77,8 +77,7 @@ export function _resolveDefaultAnimationDriver(): AnimationDriver {
*/
@NgModule({
providers: [
BROWSER_SANITIZATION_PROVIDERS,
{provide: ExceptionHandler, useFactory: _exceptionHandler, deps: []},
BROWSER_SANITIZATION_PROVIDERS, {provide: ErrorHandler, useFactory: errorHandler, deps: []},
{provide: DOCUMENT, useFactory: _document, deps: []},
{provide: EVENT_MANAGER_PLUGINS, useClass: DomEventsPlugin, multi: true},
{provide: EVENT_MANAGER_PLUGINS, useClass: KeyEventsPlugin, multi: true},
@ -95,7 +94,7 @@ export function _resolveDefaultAnimationDriver(): AnimationDriver {
export class BrowserModule {
constructor(@Optional() @SkipSelf() parentModule: BrowserModule) {
if (parentModule) {
throw new BaseException(
throw new Error(
`BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.`);
}
}

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, Inject, Injectable, OpaqueToken, RenderComponentType, Renderer, RootRenderer, ViewEncapsulation} from '@angular/core';
import {Inject, Injectable, OpaqueToken, RenderComponentType, Renderer, RootRenderer, ViewEncapsulation} from '@angular/core';
import {AnimationKeyframe, AnimationPlayer, AnimationStyles, RenderDebugInfo} from '../../core_private';
import {StringMapWrapper} from '../facade/collection';
@ -79,7 +79,7 @@ export class DomRenderer implements Renderer {
if (isString(selectorOrNode)) {
el = getDOM().querySelector(this._rootRenderer.document, selectorOrNode);
if (isBlank(el)) {
throw new BaseException(`The selector "${selectorOrNode}" did not match any elements`);
throw new Error(`The selector "${selectorOrNode}" did not match any elements`);
}
} else {
el = selectorOrNode;

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, Inject, Injectable, NgZone, OpaqueToken} from '@angular/core';
import {Inject, Injectable, NgZone, OpaqueToken} from '@angular/core';
import {ListWrapper} from '../../facade/collection';
@ -50,7 +50,7 @@ export class EventManager {
return plugin;
}
}
throw new BaseException(`No event manager plugin found for event ${eventName}`);
throw new Error(`No event manager plugin found for event ${eventName}`);
}
}

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, Inject, Injectable, OpaqueToken} from '@angular/core';
import {Inject, Injectable, OpaqueToken} from '@angular/core';
import {isPresent} from '../../facade/lang';
@ -56,7 +56,7 @@ export class HammerGesturesPlugin extends HammerGesturesPluginCommon {
if (!super.supports(eventName) && !this.isCustomEvent(eventName)) return false;
if (!isPresent((window as any /** TODO #???? */)['Hammer'])) {
throw new BaseException(`Hammer.js is not loaded, can not bind ${eventName} event`);
throw new Error(`Hammer.js is not loaded, can not bind ${eventName} event`);
}
return true;

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AUTO_STYLE, BaseException} from '@angular/core';
import {AUTO_STYLE} from '@angular/core';
import {AnimationKeyframe, AnimationPlayer, AnimationStyles, NoOpAnimationPlayer} from '../../core_private';
import {StringMapWrapper} from '../facade/collection';
@ -86,8 +86,7 @@ function _resolveStyleUnit(
if (isNumber(val)) {
unit = 'px';
} else if (_findDimensionalSuffix(val.toString()).length == 0) {
throw new BaseException(
'Please provide a CSS unit value for ' + userProvidedProp + ':' + val);
throw new Error('Please provide a CSS unit value for ' + userProvidedProp + ':' + val);
}
}
return unit;

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, Injectable, NgZone} from '@angular/core';
import {Injectable, NgZone} from '@angular/core';
import {EventEmitter} from '../../facade/async';
import {StringMapWrapper} from '../../facade/collection';
@ -35,7 +35,7 @@ export class PostMessageBusSink implements MessageBusSink {
initChannel(channel: string, runInZone: boolean = true): void {
if (StringMapWrapper.contains(this._channels, channel)) {
throw new BaseException(`${channel} has already been initialized`);
throw new Error(`${channel} has already been initialized`);
}
var emitter = new EventEmitter(false);
@ -55,7 +55,7 @@ export class PostMessageBusSink implements MessageBusSink {
if (StringMapWrapper.contains(this._channels, channel)) {
return this._channels[channel].emitter;
} else {
throw new BaseException(`${channel} is not set up. Did you forget to call initChannel?`);
throw new Error(`${channel} is not set up. Did you forget to call initChannel?`);
}
}
@ -87,7 +87,7 @@ export class PostMessageBusSource implements MessageBusSource {
initChannel(channel: string, runInZone: boolean = true) {
if (StringMapWrapper.contains(this._channels, channel)) {
throw new BaseException(`${channel} has already been initialized`);
throw new Error(`${channel} has already been initialized`);
}
var emitter = new EventEmitter(false);
@ -99,7 +99,7 @@ export class PostMessageBusSource implements MessageBusSource {
if (StringMapWrapper.contains(this._channels, channel)) {
return this._channels[channel].emitter;
} else {
throw new BaseException(`${channel} is not set up. Did you forget to call initChannel?`);
throw new Error(`${channel} is not set up. Did you forget to call initChannel?`);
}
}

View File

@ -10,7 +10,6 @@ import {Injectable, RenderComponentType, Type, ViewEncapsulation} from '@angular
import {VIEW_ENCAPSULATION_VALUES} from '../../../core_private';
import {Map, MapWrapper, StringMapWrapper} from '../../facade/collection';
import {BaseException} from '../../facade/exceptions';
import {isArray, isPresent, serializeEnum} from '../../facade/lang';
import {RenderStore} from './render_store';
import {LocationType} from './serialized_types';
@ -47,7 +46,7 @@ export class Serializer {
} else if (type === LocationType) {
return this._serializeLocation(obj);
} else {
throw new BaseException('No serializer for ' + type.toString());
throw new Error('No serializer for ' + type.toString());
}
}
@ -73,7 +72,7 @@ export class Serializer {
} else if (type === LocationType) {
return this._deserializeLocation(map);
} else {
throw new BaseException('No deserializer for ' + type.toString());
throw new Error('No deserializer for ' + type.toString());
}
}

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException} from '@angular/core';
import {EventEmitter} from '../../facade/async';
import {RenderStoreObject, Serializer} from '../shared/serializer';
@ -97,7 +96,7 @@ export class EventDispatcher {
serializedEvent = serializeTransitionEvent(event);
break;
default:
throw new BaseException(eventName + ' not supported on WebWorkers');
throw new Error(eventName + ' not supported on WebWorkers');
}
this._sink.emit({
'element': this._serializer.serialize(element, RenderStoreObject),

View File

@ -7,7 +7,7 @@
*/
import {LocationChangeListener, PlatformLocation} from '@angular/common';
import {BaseException, Injectable} from '@angular/core';
import {Injectable} from '@angular/core';
import {EventEmitter} from '../../facade/async';
import {StringMapWrapper} from '../../facade/collection';
@ -67,11 +67,11 @@ export class WebWorkerPlatformLocation extends PlatformLocation {
this._location = val;
return true;
},
(err): boolean => { throw new BaseException(err); });
(err): boolean => { throw new Error(err); });
}
getBaseHrefFromDOM(): string {
throw new BaseException(
throw new Error(
'Attempt to get base href from DOM from WebWorker. You must either provide a value for the APP_BASE_HREF token through DI or use the hash location strategy.');
}
@ -105,7 +105,7 @@ export class WebWorkerPlatformLocation extends PlatformLocation {
set pathname(newPath: string) {
if (this._location === null) {
throw new BaseException('Attempt to set pathname before value is obtained from UI');
throw new Error('Attempt to set pathname before value is obtained from UI');
}
this._location.pathname = newPath;

View File

@ -7,8 +7,7 @@
*/
import {CommonModule} from '@angular/common';
import {APP_INITIALIZER, ApplicationModule, ClassProvider, ExceptionHandler, ExistingProvider, FactoryProvider, NgModule, NgZone, PlatformRef, RootRenderer, TypeProvider, ValueProvider, createPlatformFactory, platformCore} from '@angular/core';
import {APP_INITIALIZER, ApplicationModule, ClassProvider, ErrorHandler, ExistingProvider, FactoryProvider, NgModule, NgZone, OpaqueToken, PlatformRef, ReflectiveInjector, RootRenderer, TypeProvider, ValueProvider, assertPlatform, createPlatform, createPlatformFactory, getPlatform, platformCore} from '@angular/core';
import {BROWSER_SANITIZATION_PROVIDERS} from './browser';
import {print} from './facade/lang';
import {ON_WEB_WORKER} from './web_workers/shared/api';
@ -22,18 +21,6 @@ import {WebWorkerRootRenderer} from './web_workers/worker/renderer';
import {WorkerDomAdapter} from './web_workers/worker/worker_adapter';
/**
* Logger for web workers.
*
* @experimental
*/
export class PrintLogger {
log = print;
logError = print;
logGroup = print;
logGroupEnd() {}
}
/**
* @experimental
*/
@ -44,8 +31,8 @@ export const platformWorkerApp = createPlatformFactory(platformCore, 'workerApp'
*
* @experimental
*/
export function exceptionHandler(): ExceptionHandler {
return new ExceptionHandler(new PrintLogger());
export function errorHandler(): ErrorHandler {
return new ErrorHandler();
}
// TODO(jteplitz602) remove this and compile with lib.webworker.d.ts (#3492)
@ -89,7 +76,7 @@ export function setupWebWorker(): void {
{provide: ServiceMessageBrokerFactory, useClass: ServiceMessageBrokerFactory_},
WebWorkerRootRenderer, {provide: RootRenderer, useExisting: WebWorkerRootRenderer},
{provide: ON_WEB_WORKER, useValue: true}, RenderStore,
{provide: ExceptionHandler, useFactory: exceptionHandler, deps: []},
{provide: ErrorHandler, useFactory: errorHandler, deps: []},
{provide: MessageBus, useFactory: createMessageBus, deps: [NgZone]},
{provide: APP_INITIALIZER, useValue: setupWebWorker, multi: true}
],

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, ClassProvider, ExceptionHandler, ExistingProvider, FactoryProvider, Injectable, Injector, NgZone, OpaqueToken, PLATFORM_INITIALIZER, PlatformRef, Provider, RootRenderer, Testability, TypeProvider, ValueProvider, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
import {ClassProvider, ErrorHandler, ExistingProvider, FactoryProvider, Injectable, Injector, NgZone, OpaqueToken, PLATFORM_INITIALIZER, PlatformRef, Provider, RootRenderer, Testability, TypeProvider, ValueProvider, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
import {wtfInit} from '../core_private';
@ -74,7 +74,7 @@ export const _WORKER_UI_PLATFORM_PROVIDERS: Provider[] = [
MessageBasedRenderer,
{provide: WORKER_UI_STARTABLE_MESSAGING_SERVICE, useExisting: MessageBasedRenderer, multi: true},
BROWSER_SANITIZATION_PROVIDERS,
{provide: ExceptionHandler, useFactory: _exceptionHandler, deps: []},
{provide: ErrorHandler, useFactory: _exceptionHandler, deps: []},
{provide: DOCUMENT, useFactory: _document, deps: []},
// TODO(jteplitz602): Investigate if we definitely need EVENT_MANAGER on the render thread
// #5298
@ -127,7 +127,7 @@ function initWebWorkerRenderPlatform(injector: Injector): () => void {
try {
scriptUri = injector.get(WORKER_SCRIPT);
} catch (e) {
throw new BaseException(
throw new Error(
'You must provide your WebWorker\'s initialization script with the WORKER_SCRIPT token');
}
@ -144,8 +144,8 @@ function initWebWorkerRenderPlatform(injector: Injector): () => void {
export const platformWorkerUi =
createPlatformFactory(platformCore, 'workerUi', _WORKER_UI_PLATFORM_PROVIDERS);
function _exceptionHandler(): ExceptionHandler {
return new ExceptionHandler(getDOM());
function _exceptionHandler(): ErrorHandler {
return new ErrorHandler();
}
function _document(): any {

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {APP_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, Directive, ExceptionHandler, Inject, Input, NgModule, OnDestroy, PLATFORM_INITIALIZER, Pipe, Provider, createPlatformFactory} from '@angular/core';
import {APP_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, Directive, ErrorHandler, Inject, Input, NgModule, OnDestroy, PLATFORM_INITIALIZER, Pipe, Provider, createPlatformFactory} from '@angular/core';
import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref';
import {Console} from '@angular/core/src/console';
import {ComponentRef} from '@angular/core/src/linker/component_factory';
@ -94,12 +94,9 @@ class HelloCmpUsingPlatformDirectiveAndPipe {
class HelloCmpUsingCustomElement {
}
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(){};
error(s: any): void { this.res.push(s); }
}
@ -160,10 +157,11 @@ export function main() {
it('should throw if no element is found',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var logger = new _ArrayLogger();
var exceptionHandler = new ExceptionHandler(logger, false);
var logger = new MockConsole();
var errorHandler = new ErrorHandler(false);
errorHandler._console = logger as any;
bootstrap(HelloRootCmp, [
{provide: ExceptionHandler, useValue: exceptionHandler}
{provide: ErrorHandler, useValue: errorHandler}
]).then(null, (reason) => {
expect(reason.message).toContain('The selector "hello-app" did not match any elements');
async.done();
@ -174,11 +172,12 @@ export function main() {
if (getDOM().supportsDOMEvents()) {
it('should forward the error to promise when bootstrap fails',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var logger = new _ArrayLogger();
var exceptionHandler = new ExceptionHandler(logger, false);
var logger = new MockConsole();
var errorHandler = new ErrorHandler(false);
errorHandler._console = logger as any;
var refPromise =
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
bootstrap(HelloRootCmp, [{provide: ErrorHandler, useValue: errorHandler}]);
refPromise.then(null, (reason: any) => {
expect(reason.message)
.toContain('The selector "hello-app" did not match any elements');
@ -188,11 +187,12 @@ export function main() {
it('should invoke the default exception handler when bootstrap fails',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
var logger = new _ArrayLogger();
var exceptionHandler = new ExceptionHandler(logger, false);
var logger = new MockConsole();
var errorHandler = new ErrorHandler(false);
errorHandler._console = logger as any;
var refPromise =
bootstrap(HelloRootCmp, [{provide: ExceptionHandler, useValue: exceptionHandler}]);
bootstrap(HelloRootCmp, [{provide: ErrorHandler, useValue: errorHandler}]);
refPromise.then(null, (reason) => {
expect(logger.res.join(''))
.toContain('The selector "hello-app" did not match any elements');

View File

@ -11,7 +11,6 @@ import {NgZone} from '@angular/core/src/zone/ng_zone';
import {ClientMessageBroker, ClientMessageBrokerFactory_, UiArguments} from '@angular/platform-browser/src/web_workers/shared/client_message_broker';
import {MessageBus, MessageBusSink, MessageBusSource} from '@angular/platform-browser/src/web_workers/shared/message_bus';
import {ListWrapper, StringMapWrapper} from '../../../src/facade/collection';
import {BaseException} from '../../../src/facade/exceptions';
import {isPresent} from '../../../src/facade/lang';
import {SpyMessageBroker} from '../worker/spies';
@ -89,7 +88,7 @@ export class MockMessageBusSource implements MessageBusSource {
from(channel: string): MockEventEmitter<any> {
if (!StringMapWrapper.contains(this._channels, channel)) {
throw new BaseException(`${channel} is not set up. Did you forget to call initChannel?`);
throw new Error(`${channel} is not set up. Did you forget to call initChannel?`);
}
return this._channels[channel];
}

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException} from '@angular/core';
import {BrowserDomAdapter} from '../src/browser/browser_adapter';
import {document, window} from '../src/facade/browser';
@ -33,7 +32,7 @@ export function getStringParameter(name: string) {
}
if (isBlank(value)) {
throw new BaseException(`Could not find and input field with name ${name}`);
throw new Error(`Could not find and input field with name ${name}`);
}
return value;