Skip to content

Commit 8ecb632

Browse files
committed
feat(lang): added "context" to BaseException
1 parent 8ad4ad5 commit 8ecb632

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

modules/angular2/src/core/application.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ function _createNgZone(givenReporter: Function): NgZone {
145145
var defaultErrorReporter = (exception, stackTrace) => {
146146
var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n");
147147
DOM.logError(`${exception}\n\n${longStackTrace}`);
148+
149+
if (exception instanceof BaseException && isPresent(exception.context)) {
150+
print("Error Context:");
151+
print(exception.context);
152+
}
148153
throw exception;
149154
};
150155

modules/angular2/src/facade/lang.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,12 @@ class FunctionWrapper {
183183
}
184184

185185
class BaseException extends Error {
186+
final dynamic context;
186187
final String message;
187188
final originalException;
188189
final originalStack;
189190

190-
BaseException([this.message, this.originalException, this.originalStack]);
191+
BaseException([this.message, this.originalException, this.originalStack, this.context]);
191192

192193
String toString() {
193194
return this.message;
@@ -225,7 +226,7 @@ bool isJsObject(o) {
225226

226227
var _assertionsEnabled = null;
227228
bool assertionsEnabled() {
228-
if (_assertionsEnabled == null) {
229+
if (_assertionsEnabled == null) {
229230
try {
230231
assert(false);
231232
_assertionsEnabled = false;

modules/angular2/src/facade/lang.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ export function getTypeNameForDebugging(type: Type): string {
1111

1212
export class BaseException extends Error {
1313
stack;
14-
constructor(public message?: string, public originalException?, public originalStack?) {
14+
constructor(public message?: string, private _originalException?, private _originalStack?,
15+
private _context?) {
1516
super(message);
1617
this.stack = (<any>new Error(message)).stack;
1718
}
1819

20+
get originalException(): any { return this._originalException; }
21+
22+
get originalStack(): any { return this._originalStack; }
23+
24+
get context(): any { return this._context; }
25+
1926
toString(): string { return this.message; }
2027
}
2128

@@ -118,7 +125,9 @@ export function stringify(token): string {
118125
return token.name;
119126
}
120127

121-
return token.toString();
128+
var res = token.toString();
129+
var newLineIndex = res.indexOf("\n");
130+
return (newLineIndex === -1) ? res : res.substring(0, newLineIndex);
122131
}
123132

124133
export class StringWrapper {

0 commit comments

Comments
 (0)