Skip to content

Commit a5bf30c

Browse files
davidmorgancommit-bot@chromium.org
authored andcommitted
Revert "Fail synchronously if null is passed as an error to async APIs."
This reverts commit bef363b. Reason for revert: Breaks google3 tests, see b/151204525. Original change's description: > Fail synchronously if null is passed as an error to async APIs. > > The first patchset is Lasse's original changes. > > Change-Id: Ic5f24bcfc0ef4e82edee68d61e015b095cb5916e > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138605 > Reviewed-by: Leaf Petersen <[email protected]> [email protected],[email protected] Change-Id: Ie17c35e9d23c70a7aecd1ef292962154cf6f007d No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138925 Reviewed-by: David Morgan <[email protected]> Commit-Queue: David Morgan <[email protected]>
1 parent e6a1e70 commit a5bf30c

27 files changed

+31
-160
lines changed

sdk/lib/_http/websocket_impl.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class _WebSocketProtocolTransformer extends StreamTransformerBase<List<int>,
115115
}
116116

117117
void addError(Object error, [StackTrace stackTrace]) {
118-
ArgumentError.checkNotNull(error, "error");
119118
_eventSink.addError(error, stackTrace);
120119
}
121120

@@ -724,7 +723,6 @@ class _WebSocketOutgoingTransformer
724723
}
725724

726725
void addError(Object error, [StackTrace stackTrace]) {
727-
ArgumentError.checkNotNull(error, "error");
728726
_eventSink.addError(error, stackTrace);
729727
}
730728

sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ class _AsyncStarImpl<T> {
419419
}
420420

421421
void addError(Object error, StackTrace stackTrace) {
422-
ArgumentError.checkNotNull(error, "error");
423422
if (cancellationCompleter != null && !cancellationCompleter.isCompleted) {
424423
// If the stream has been cancelled, complete the cancellation future
425424
// with the error.

sdk/lib/_internal/vm/lib/async_patch.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ class _AsyncStarStreamController<T> {
209209
}
210210

211211
void addError(Object error, StackTrace stackTrace) {
212-
ArgumentError.checkNotNull(error, "error");
213212
if ((cancellationFuture != null) && cancellationFuture._mayComplete) {
214213
// If the stream has been cancelled, complete the cancellation future
215214
// with the error.

sdk/lib/async/broadcast_stream_controller.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ abstract class _BroadcastStreamController<T>
253253
}
254254

255255
void addError(Object error, [StackTrace stackTrace]) {
256-
ArgumentError.checkNotNull(error, "error");
256+
error = _nonNullError(error);
257257
if (!_mayAddEvent) throw _addEventError();
258258
AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
259259
if (replacement != null) {
@@ -480,7 +480,6 @@ class _AsBroadcastStreamController<T> extends _SyncBroadcastStreamController<T>
480480
}
481481

482482
void addError(Object error, [StackTrace stackTrace]) {
483-
ArgumentError.checkNotNull(error, "error");
484483
if (!isClosed && _isFiring) {
485484
_addPendingEvent(new _DelayedError(error, stackTrace));
486485
return;

sdk/lib/async/future.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ abstract class Future<T> {
266266
* If an error handler isn't added before the future completes, the error
267267
* will be considered unhandled.
268268
*
269-
* The [error] must not be `null`.
269+
* If [error] is `null`, it is replaced by a [NullThrownError].
270270
*
271271
* Use [Completer] to create a future and complete it later.
272272
*/
273273
factory Future.error(Object error, [StackTrace stackTrace]) {
274-
ArgumentError.checkNotNull(error, "error");
274+
error = _nonNullError(error);
275275
if (!identical(Zone.current, _rootZone)) {
276276
AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
277277
if (replacement != null) {
@@ -874,7 +874,7 @@ abstract class Completer<T> {
874874
* Completing a future with an error indicates that an exception was thrown
875875
* while trying to produce a value.
876876
*
877-
* The [error] must not be `null`.
877+
* If [error] is `null`, it is replaced by a [NullThrownError].
878878
*
879879
* If `error` is a `Future`, the future itself is used as the error value.
880880
* If you want to complete with the result of the future, you can use:

sdk/lib/async/future_impl.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class _Completer<T> implements Completer<T> {
1919
void complete([FutureOr<T> value]);
2020

2121
void completeError(Object error, [StackTrace stackTrace]) {
22-
ArgumentError.checkNotNull(error, "error");
22+
error = _nonNullError(error);
2323
if (!future._mayComplete) throw new StateError("Future already completed");
2424
AsyncError replacement = Zone.current.errorCallback(error, stackTrace);
2525
if (replacement != null) {
@@ -94,8 +94,8 @@ class _FutureListener<S, T> {
9494
this.result, _FutureOnValue<S, T> onValue, Function errorCallback)
9595
: callback = onValue,
9696
errorCallback = errorCallback,
97-
state = ((errorCallback == null) ? stateThen : stateThenOnerror) |
98-
stateIsAwait;
97+
state = ((errorCallback == null) ? stateThen : stateThenOnerror)
98+
| stateIsAwait ;
9999

100100
_FutureListener.catchError(this.result, this.errorCallback, this.callback)
101101
: state = (callback == null) ? stateCatcherror : stateCatcherrorTest;
@@ -293,7 +293,8 @@ class _Future<T> implements Future<T> {
293293
/// The system created liseners are not registered in the zone,
294294
/// and the listener is marked as being from an `await`.
295295
/// This marker is used in [_continuationFunctions].
296-
Future<E> _thenAwait<E>(FutureOr<E> f(T value), Function onError) {
296+
Future<E> _thenAwait<E>(
297+
FutureOr<E> f(T value), Function onError) {
297298
_Future<E> result = new _Future<E>();
298299
_addListener(new _FutureListener<T, E>.thenAwait(result, f, onError));
299300
return result;
@@ -811,5 +812,5 @@ Function _registerErrorHandler(Function errorHandler, Zone zone) {
811812
errorHandler,
812813
"onError",
813814
"Error handler must accept one Object or one Object and a StackTrace"
814-
" as arguments, and return a a valid result");
815+
" as arguments, and return a a valid result");
815816
}

sdk/lib/async/stream.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ abstract class Stream<T> {
132132
*
133133
* This stream emits a single error event of [error] and [stackTrace]
134134
* and then completes with a done event.
135-
* The [error] must not be `null`.
136135
*
137136
* Example:
138137
* ```dart
@@ -153,13 +152,11 @@ abstract class Stream<T> {
153152
* stack trace as well.
154153
*/
155154
@Since("2.5")
156-
factory Stream.error(Object error, [StackTrace stackTrace]) {
157-
ArgumentError.checkNotNull(error, "error");
158-
return (_AsyncStreamController<T>(null, null, null, null)
159-
.._addError(error, stackTrace)
160-
.._closeUnchecked())
161-
.stream;
162-
}
155+
factory Stream.error(Object error, [StackTrace stackTrace]) =>
156+
(_AsyncStreamController<T>(null, null, null, null)
157+
.._addError(error, stackTrace)
158+
.._closeUnchecked())
159+
.stream;
163160

164161
/**
165162
* Creates a new single-subscription stream from the future.
@@ -1814,8 +1811,6 @@ abstract class EventSink<T> implements Sink<T> {
18141811
/**
18151812
* Adds an [error] to the sink.
18161813
*
1817-
* The [error] must not be `null`.
1818-
*
18191814
* Must not be called on a closed sink.
18201815
*/
18211816
void addError(Object error, [StackTrace stackTrace]);

sdk/lib/async/stream_controller.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ abstract class StreamController<T> implements StreamSink<T> {
237237
/**
238238
* Sends or enqueues an error event.
239239
*
240-
* The [error] must not be `null`.
240+
* If [error] is `null`, it is replaced by a [NullThrownError].
241241
*
242242
* Listeners receive this event at a later microtask. This behavior can be
243243
* overridden by using `sync` controllers. Note, however, that sync
@@ -361,8 +361,6 @@ abstract class SynchronousStreamController<T> implements StreamController<T> {
361361
/**
362362
* Adds error to the controller's stream.
363363
*
364-
* The [error] must not be `null`.
365-
*
366364
* As [StreamController.addError], but must not be called while an event is
367365
* being added by [add], [addError] or [close].
368366
*/
@@ -599,11 +597,8 @@ abstract class _StreamController<T> implements _StreamControllerBase<T> {
599597

600598
/**
601599
* Send or enqueue an error event.
602-
*
603-
* The [error] must not be `null`.
604600
*/
605601
void addError(Object error, [StackTrace stackTrace]) {
606-
ArgumentError.checkNotNull(error, "error");
607602
if (!_mayAddEvent) throw _badEventState();
608603
error = _nonNullError(error);
609604
AsyncError replacement = Zone.current.errorCallback(error, stackTrace);

sdk/lib/async/stream_transformers.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ class _HandlerEventSink<S, T> implements EventSink<S> {
234234
}
235235

236236
void addError(Object error, [StackTrace stackTrace]) {
237-
ArgumentError.checkNotNull(error, "error");
238237
if (_isClosed) {
239238
throw StateError("Sink is closed");
240239
}

sdk/lib/async/zone.dart

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ class AsyncError implements Error {
4343
final Object error;
4444
final StackTrace stackTrace;
4545

46-
AsyncError(this.error, this.stackTrace) {
47-
ArgumentError.checkNotNull(error, "error");
48-
}
46+
AsyncError(this.error, this.stackTrace);
4947

5048
String toString() => '$error';
5149
}
@@ -752,7 +750,6 @@ class _ZoneDelegate implements ZoneDelegate {
752750
}
753751

754752
AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace) {
755-
ArgumentError.checkNotNull(error, "error");
756753
var implementation = _delegationTarget._errorCallback;
757754
_Zone implZone = implementation.zone;
758755
if (identical(implZone, _rootZone)) return null;
@@ -1068,7 +1065,6 @@ class _CustomZone extends _Zone {
10681065
}
10691066

10701067
AsyncError errorCallback(Object error, StackTrace stackTrace) {
1071-
ArgumentError.checkNotNull(error, "error");
10721068
var implementation = this._errorCallback;
10731069
assert(implementation != null);
10741070
final Zone implementationZone = implementation.zone;
@@ -1113,11 +1109,8 @@ class _CustomZone extends _Zone {
11131109

11141110
void _rootHandleUncaughtError(
11151111
Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) {
1116-
if (error == null) {
1117-
error = ArgumentError.notNull("error");
1118-
stackTrace = StackTrace.current;
1119-
}
11201112
_schedulePriorityAsyncCallback(() {
1113+
error ??= new NullThrownError();
11211114
if (stackTrace == null) throw error;
11221115
_rethrow(error, stackTrace);
11231116
});

0 commit comments

Comments
 (0)