Skip to content

Future.catchError's doc example doesn't emphasize that a valid T must be returned #50430

Open
@srawlins

Description

@srawlins

The current docs for Future.catchError include this example:

Future.delayed(
  const Duration(seconds: 1),
  () => throw 401,
).then((value) {
  throw 'Unreachable';
}).catchError((err) {
  print('Error: $err'); // Prints 401.
}, test: (error) {
  return error is int && error >= 400;
});

I believe this involves a Future<dynamic>. The catchError onError callback is then allowed to omit a return, as null is a valid dynamic. But it would benefit the user to change this example to use a non-nullable type T, to show that a T must be returned in catchError's onError.

We now catch this statically with a Hint, body_might_complete_normally_catch_error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-coretype-documentationA request to add or improve documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions