fix(errors): require passing stack traces explicitly in ng2 own code

This commit is contained in:
Yegor Jbanov
2015-05-19 12:48:00 -07:00
parent 5c88f662cd
commit 8ab773538b
11 changed files with 112 additions and 75 deletions
+13 -10
View File
@@ -6,9 +6,13 @@ export 'dart:async' show Future, Stream, StreamController, StreamSubscription;
class PromiseWrapper {
static Future resolve(obj) => new Future.value(obj);
static Future reject(obj) => new Future.error(
static Future reject(obj, stackTrace) => new Future.error(
obj,
obj is Error ? obj.stackTrace : null);
stackTrace != null
? stackTrace
: obj is Error
? obj.stackTrace
: null);
static Future<List> all(List<Future> promises) => Future.wait(promises);
@@ -23,7 +27,7 @@ class PromiseWrapper {
return promise.catchError(onError);
}
static _Completer completer() => new _Completer(new Completer());
static CompleterWrapper completer() => new CompleterWrapper(new Completer());
// TODO(vic): create a TimerWrapper
static Timer setTimeout(fn(), int millis)
@@ -99,10 +103,10 @@ class EventEmitter extends Stream {
}
}
class _Completer {
class CompleterWrapper {
final Completer c;
_Completer(this.c);
CompleterWrapper(this.c);
Future get promise => c.future;
@@ -110,11 +114,10 @@ class _Completer {
c.complete(v);
}
void reject(v) {
var stack = null;
if (v is Error) {
stack = v.stackTrace;
void reject(error, stack) {
if (stack == null && error is Error) {
stack = error.stackTrace;
}
c.completeError(v, stack);
c.completeError(error, stack);
}
}
+2 -2
View File
@@ -15,7 +15,7 @@ export var Promise = (<any>global).Promise;
export class PromiseWrapper {
static resolve(obj): Promise<any> { return Promise.resolve(obj); }
static reject(obj): Promise<any> { return Promise.reject(obj); }
static reject(obj, _): Promise<any> { return Promise.reject(obj); }
// Note: We can't rename this method into `catch`, as this is not a valid
// method name in Dart.
@@ -29,7 +29,7 @@ export class PromiseWrapper {
}
static then<T>(promise: Promise<T>, success: (value: any) => T | Thenable<T>,
rejection: (error: any) => T | Thenable<T>): Promise<T> {
rejection: (error: any, stack?: any) => T | Thenable<T>): Promise<T> {
return promise.then(success, rejection);
}