Chromium Code Reviews| Index: sdk/lib/async/stream.dart |
| diff --git a/sdk/lib/async/stream.dart b/sdk/lib/async/stream.dart |
| index 495d04790ae894487d9df70dfdd48da98fda83fd..2de8566cdfb75378540efc1138c8f8ac4ce56e7e 100644 |
| --- a/sdk/lib/async/stream.dart |
| +++ b/sdk/lib/async/stream.dart |
| @@ -191,13 +191,19 @@ abstract class Stream<T> { |
| * On errors from this stream, the [onError] handler is given a |
| * object describing the error. |
| * |
| + * The [onError] callback must be of type `void onError(error)` or |
| + * `void onError(error, StackTrace stackTrace)`. Depending on the function |
| + * type the the stream either invokes [onError] with or without a stack |
| + * trace. The stack trace argument might be `null` if the stream itself |
| + * received an error without stack trace. |
| + * |
| * If this stream closes, the [onDone] handler is called. |
| * |
| * If [cancelOnError] is true, the subscription is ended when |
| * the first error is reported. The default is false. |
| */ |
| StreamSubscription<T> listen(void onData(T event), |
| - { void onError(error), |
| + { Function onError, |
| void onDone(), |
| bool cancelOnError}); |
| @@ -225,6 +231,12 @@ abstract class Stream<T> { |
| * If this stream sends an error that matches [test], then it is intercepted |
| * by the [handle] function. |
| * |
| + * The [onError] callback must be of type `void onError(error)` or |
| + * `void onError(error, StackTrace stackTrace)`. Depending on the function |
| + * type the the stream either invokes [onError] with or without a stack |
| + * trace. The stack trace argument might be `null` if the stream itself |
| + * received an error without stack trace. |
|
Lasse Reichstein Nielsen
2013/10/04 08:45:17
"without a stack trace".
What happens if onError
floitsch
2013/10/05 18:11:48
That's an error ;)
Lasse Reichstein Nielsen
2013/10/07 11:55:48
Ah, it's an error, but we don't say which error it
|
| + * |
| * An [AsyncError] [:e:] is matched by a test function if [:test(e):] returns |
| * true. If [test] is omitted, every error is considered matching. |
| * |
| @@ -236,8 +248,8 @@ abstract class Stream<T> { |
| * [Stream.transform] to handle the event by writing a data event to |
| * the output sink |
| */ |
| - Stream<T> handleError(void handle( error), { bool test(error) }) { |
| - return new _HandleErrorStream<T>(this, handle, test); |
| + Stream<T> handleError(Function onError, { bool test(error) }) { |
| + return new _HandleErrorStream<T>(this, onError, test); |
| } |
| /** |
| @@ -313,8 +325,8 @@ abstract class Stream<T> { |
| _cancelAndError(subscription, result) |
| ); |
| }, |
| - onError: (e) { |
| - result._completeError(e); |
| + onError: (e, st) { |
| + result._completeError(e, st); |
| }, |
| onDone: () { |
| result._complete(value); |
| @@ -887,7 +899,7 @@ abstract class StreamSubscription<T> { |
| void onData(void handleData(T data)); |
| /** Set or override the error event handler of this subscription. */ |
| - void onError(void handleError(error)); |
| + void onError(Function handleError); |
| /** Set or override the done event handler of this subscription. */ |
| void onDone(void handleDone()); |
| @@ -958,7 +970,7 @@ class StreamView<T> extends Stream<T> { |
| => _stream.asBroadcastStream(onListen: onListen, onCancel: onCancel); |
| StreamSubscription<T> listen(void onData(T value), |
| - { void onError(error), |
| + { Function onError, |
| void onDone(), |
| bool cancelOnError }) { |
| return _stream.listen(onData, onError: onError, onDone: onDone, |
| @@ -1041,7 +1053,7 @@ abstract class StreamTransformer<S, T> { |
| */ |
| factory StreamTransformer({ |
| void handleData(S data, EventSink<T> sink), |
| - void handleError(error, EventSink<T> sink), |
| + Function handleError, |
| void handleDone(EventSink<T> sink)}) { |
| return new _StreamTransformerImpl<S, T>(handleData, |
| handleError, |
| @@ -1134,7 +1146,7 @@ class EventTransformStream<S, T> extends Stream<T> { |
| : _source = source, _transformer = transformer; |
| StreamSubscription<T> listen(void onData(T data), |
| - { void onError(error), |
| + { Function onError, |
| void onDone(), |
| bool cancelOnError }) { |
| if (onData == null) onData = _nullDataHandler; |
| @@ -1164,7 +1176,7 @@ class _EventTransformStreamSubscription<S, T> |
| _EventTransformStreamSubscription(Stream<S> source, |
| this._transformer, |
| void onData(T data), |
| - void onError(error), |
| + Function onError, |
| void onDone(), |
| bool cancelOnError) |
| : super(onData, onError, onDone, cancelOnError) { |
| @@ -1198,15 +1210,19 @@ class _EventTransformStreamSubscription<S, T> |
| try { |
| _transformer.handleData(data, _sink); |
| } catch (e, s) { |
| - _addError(_asyncError(e, s)); |
| + _addError(_asyncError(e, s), s); |
| } |
| } |
| - void _handleError(error) { |
| + void _handleError(error, [stackTrace]) { |
| try { |
| _transformer.handleError(error, _sink); |
| } catch (e, s) { |
| - _addError(_asyncError(e, s)); |
| + if (identical(e, error)) { |
| + _addError(error, stackTrace); |
| + } else { |
| + _addError(_asyncError(e, s), s); |
| + } |
| } |
| } |
| @@ -1215,7 +1231,7 @@ class _EventTransformStreamSubscription<S, T> |
| _subscription = null; |
| _transformer.handleDone(_sink); |
| } catch (e, s) { |
| - _addError(_asyncError(e, s)); |
| + _addError(_asyncError(e, s), s); |
| } |
| } |
| } |
| @@ -1225,7 +1241,9 @@ class _EventSinkAdapter<T> implements EventSink<T> { |
| _EventSinkAdapter(this._sink); |
| void add(T data) { _sink._add(data); } |
| - void addError(error) { _sink._addError(error); } |
| + void addError(error, [StackTrace stackTrace]) { |
| + _sink._addError(error, stackTrace); |
| + } |
| void close() { _sink._close(); } |
| } |