feat(exception_handler): print originalException and originalStack for all exceptions
This commit is contained in:
@ -31,6 +31,7 @@ import {AnchorBasedAppRootUrl} from 'angular2/src/services/anchor_based_app_root
|
||||
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
|
||||
import {Injectable} from 'angular2/di';
|
||||
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
|
||||
/**
|
||||
* Creates a zone, sets up the DI bindings
|
||||
@ -38,7 +39,7 @@ import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
|
||||
*/
|
||||
export function bootstrapUICommon(bus: MessageBus) {
|
||||
BrowserDomAdapter.makeCurrent();
|
||||
var zone = createNgZone(new ExceptionHandler());
|
||||
var zone = createNgZone(new ExceptionHandler(DOM));
|
||||
zone.run(() => {
|
||||
var injector = createInjector(zone);
|
||||
var webWorkerMain = injector.get(WebWorkerMain);
|
||||
|
@ -62,13 +62,18 @@ import {RenderProtoViewRefStore} from 'angular2/src/web-workers/shared/render_pr
|
||||
import {
|
||||
RenderViewWithFragmentsStore
|
||||
} from 'angular2/src/web-workers/shared/render_view_with_fragments_store';
|
||||
import {WorkerExceptionHandler} from 'angular2/src/web-workers/worker/exception_handler';
|
||||
|
||||
var _rootInjector: Injector;
|
||||
|
||||
// Contains everything that is safe to share between applications.
|
||||
var _rootBindings = [bind(Reflector).toValue(reflector)];
|
||||
|
||||
class PrintLogger {
|
||||
log = print;
|
||||
logGroup = print;
|
||||
logGroupEnd() {}
|
||||
}
|
||||
|
||||
function _injectorBindings(appComponentType, bus: WorkerMessageBus,
|
||||
initData: StringMap<string, any>): List<Type | Binding | List<any>> {
|
||||
var bestChangeDetection: Type = DynamicChangeDetection;
|
||||
@ -118,8 +123,7 @@ function _injectorBindings(appComponentType, bus: WorkerMessageBus,
|
||||
DirectiveResolver,
|
||||
Parser,
|
||||
Lexer,
|
||||
WorkerExceptionHandler,
|
||||
bind(ExceptionHandler).toAlias(WorkerExceptionHandler),
|
||||
bind(ExceptionHandler).toFactory(() => {new ExceptionHandler(new PrintLogger())}),
|
||||
bind(XHR).toValue(new XHRImpl()),
|
||||
ComponentUrlMapper,
|
||||
UrlResolver,
|
||||
@ -135,7 +139,7 @@ export function bootstrapWebworkerCommon(
|
||||
componentInjectableBindings: List<Type | Binding | List<any>> = null): Promise<ApplicationRef> {
|
||||
var bootstrapProcess = PromiseWrapper.completer();
|
||||
|
||||
var zone = createNgZone(new WorkerExceptionHandler());
|
||||
var zone = createNgZone(new ExceptionHandler(new PrintLogger()));
|
||||
zone.run(() => {
|
||||
// TODO(rado): prepopulate template cache, so applications with only
|
||||
// index.html and main.js are possible.
|
||||
|
@ -1,35 +0,0 @@
|
||||
import {isPresent, print, BaseException} from 'angular2/src/facade/lang';
|
||||
import {ListWrapper, isListLikeIterable} from 'angular2/src/facade/collection';
|
||||
import {ExceptionHandler} from 'angular2/src/core/exception_handler';
|
||||
import {Injectable} from 'angular2/di';
|
||||
|
||||
@Injectable()
|
||||
export class WorkerExceptionHandler implements ExceptionHandler {
|
||||
logError: Function = print;
|
||||
|
||||
call(exception: Object, stackTrace: any = null, reason: string = null) {
|
||||
var longStackTrace = isListLikeIterable(stackTrace) ?
|
||||
(<any>stackTrace).join("\n\n-----async gap-----\n") :
|
||||
stackTrace;
|
||||
|
||||
this.logError(`${exception}\n\n${longStackTrace}`);
|
||||
|
||||
if (isPresent(reason)) {
|
||||
this.logError(`Reason: ${reason}`);
|
||||
}
|
||||
|
||||
var context = this._findContext(exception);
|
||||
if (isPresent(context)) {
|
||||
this.logError("Error Context:");
|
||||
this.logError(context);
|
||||
}
|
||||
|
||||
throw exception;
|
||||
}
|
||||
|
||||
_findContext(exception: any): any {
|
||||
if (!(exception instanceof BaseException)) return null;
|
||||
return isPresent(exception.context) ? exception.context :
|
||||
this._findContext(exception.originalException);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user