Skip to content

Commit ead21c9

Browse files
committed
fix(exception_handler): log errors via console.error
This is e.g. needed as we use this to test for errors in our examples.
1 parent 87dcd5e commit ead21c9

File tree

10 files changed

+52
-20
lines changed

10 files changed

+52
-20
lines changed

modules/angular2/src/core/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function _injectorBindings(appComponentType): List<Binding> {
134134
function _createVmZone(givenReporter:Function): VmTurnZone {
135135
var defaultErrorReporter = (exception, stackTrace) => {
136136
var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n");
137-
print(`${exception}\n\n${longStackTrace}`);
137+
DOM.logError(`${exception}\n\n${longStackTrace}`);
138138
throw exception;
139139
};
140140

modules/angular2/src/core/exception_handler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Injectable} from 'angular2/di';
22
import {isPresent, print} from 'angular2/src/facade/lang';
33
import {ListWrapper, isListLikeIterable} from 'angular2/src/facade/collection';
4+
import {DOM} from 'angular2/src/dom/dom_adapter';
45

56
/**
67
* Provides a hook for centralized exception handling.
@@ -36,6 +37,6 @@ export class ExceptionHandler {
3637
call(error, stackTrace = null, reason = null) {
3738
var longStackTrace = isListLikeIterable(stackTrace) ? ListWrapper.join(stackTrace, "\n\n") : stackTrace;
3839
var reasonStr = isPresent(reason) ? `\n${reason}` : '';
39-
print(`${error}${reasonStr}\nSTACKTRACE:\n${longStackTrace}`);
40+
DOM.logError(`${error}${reasonStr}\nSTACKTRACE:\n${longStackTrace}`);
4041
}
4142
}

modules/angular2/src/dom/browser_adapter.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
100100
setRootDomAdapter(new BrowserDomAdapter());
101101
}
102102

103+
logError(error) {
104+
window.console.error(error);
105+
}
106+
103107
@override
104108
Map<String, String> get attrToPropMap => const <String, String>{
105109
'innerHtml': 'innerHtml',

modules/angular2/src/dom/browser_adapter.es6

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
5757
setRootDomAdapter(new BrowserDomAdapter());
5858
}
5959

60+
logError(error) {
61+
window.console.error(error);
62+
}
63+
6064
get attrToPropMap() {
6165
return _attrToPropMap;
6266
}

modules/angular2/src/dom/dom_adapter.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ function _abstract() {
1616
@ABSTRACT()
1717
export class DomAdapter {
1818

19+
logError(error) {
20+
throw _abstract();
21+
}
22+
1923
/**
2024
* Maps attribute names to their corresponding property names for cases
2125
* where attribute name doesn't match property name.

modules/angular2/src/dom/html_adapter.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ library angular2.dom.htmlAdapter;
33
import 'dom_adapter.dart';
44
import 'package:html/parser.dart' as parser;
55
import 'package:html/dom.dart';
6+
import 'dart:io';
67

78
class Html5LibDomAdapter implements DomAdapter {
89
static void makeCurrent() {
910
setRootDomAdapter(new Html5LibDomAdapter());
1011
}
1112

13+
logError(error) {
14+
stderr.writeln('${error}');
15+
}
16+
1217
@override
1318
final attrToPropMap = const {
1419
'innerHtml': 'innerHtml',

modules/angular2/src/dom/parse5_adapter.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export class Parse5DomAdapter extends DomAdapter {
2828
setRootDomAdapter(new Parse5DomAdapter());
2929
}
3030

31+
logError(error) {
32+
console.error(error);
33+
}
34+
3135
get attrToPropMap() {
3236
return _attrToPropMap;
3337
}

modules/examples/e2e_test/sourcemap/sourcemap_spec.es6

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ describe('sourcemaps', function () {
66

77
it('should map sources', function() {
88
browser.get(URL);
9+
10+
$('error-app .errorButton').click();
11+
912
// TODO(tbosch): Bug in ChromeDriver: Need to execute at least one command
1013
// so that the browser logs can be read out!
1114
browser.executeScript('1+1');
1215
browser.manage().logs().get('browser').then(function(logs) {
1316
var errorLine = null;
1417
var errorColumn = null;
1518
logs.forEach(function(log) {
16-
var match = /Test\.run\s+\(.+:(\d+):(\d+)/m.exec(log.message);
19+
var match = /\.createError\s+\(.+:(\d+):(\d+)/m.exec(log.message);
1720
if (match) {
1821
errorLine = parseInt(match[1]);
1922
errorColumn = parseInt(match[2]);

modules/examples/src/sourcemap/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
<html>
33
<title>Sourcemaps</title>
44
<body>
5+
<error-app>
6+
Loading...
7+
</error-app>
8+
9+
<p>
510
Please look into the console and check whether the stack trace is mapped
611
via source maps!
12+
</p>
13+
714
$SCRIPTS$
815
</body>
916
</html>
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { BaseException, print, CONST } from 'angular2/src/facade/lang';
2+
import { bootstrap } from 'angular2/angular2';
3+
// TODO(radokirov): Once the application is transpiled by TS instead of Traceur,
4+
// add those imports back into 'angular2/angular2';
5+
import {Component} from 'angular2/src/core/annotations_impl/annotations';
6+
import {View} from 'angular2/src/core/annotations_impl/view';
27

3-
class TestAnnotation {
4-
@CONST()
5-
constructor() {}
6-
}
7-
8-
// Use a class with an annotation,
9-
// as this is where we expect the most source code changes
10-
// through compilation.
11-
@TestAnnotation()
12-
class Test {
13-
run() {
14-
try {
15-
throw new BaseException('Sourcemap test');
16-
} catch (e) {
17-
print(e);
18-
}
8+
@Component({
9+
selector: 'error-app',
10+
})
11+
@View({
12+
template: `
13+
<button class="errorButton" (click)="createError()">create error</button>`,
14+
directives: []
15+
})
16+
export class ErrorComponent {
17+
createError() {
18+
throw new BaseException('Sourcemap test');
1919
}
2020
}
2121

2222
export function main() {
23-
new Test().run();
23+
bootstrap(ErrorComponent);
2424
}

0 commit comments

Comments
 (0)