Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Return valid type from Future.catchError.
Browse files Browse the repository at this point in the history
An upcoming feature to the Dart analyzer [0] will report Future.catchError [1]
`onError` handlers which return values of invalid type. Currently this is not
reported because the `onError` handler function type cannot be accurately
expressed. An `onError` handler for `Future<T>.catchError` must be either
`FutureOr<T> Function(dynamic)` or `FutureOr<T> Function(dynamic, StackTrace)`.
In either case, the return type of the function is `FutureOr<T>`.

This CL corrects `onError` handler(s) to return a value of a valid type (typically `null`).

[0]: dart-lang/sdk#35825
[1]: https://api.dart.dev/dev/2.12.0-149.0.dev/dart-async/Future/catchError.html
  • Loading branch information
srawlins committed Dec 22, 2020
1 parent 53e002a commit 17abe7a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/src/usage_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ class AnalyticsImpl implements Analytics {
Stream<Map<String, dynamic>> get onSend => _sendController.stream;

@override
Future waitForLastPing({Duration? timeout}) {
Future f = Future.wait(_futures).catchError((e) => null);
Future<List<dynamic>> waitForLastPing({Duration? timeout}) {
var f = Future.wait(_futures).catchError((e) => []);

if (timeout != null) {
f = f.timeout(timeout, onTimeout: () => []);
Expand Down

0 comments on commit 17abe7a

Please sign in to comment.