Skip to content

Add lint for missing await when returning a value inside a try / catch block #58510

@cubuspl42

Description

@cubuspl42

Describe the rule you'd like to see implemented

I'd love to have a lint that detects missing await keyword after return in try / on / catch blocks of async functions.

Without the await keyword in the try block, the on / catch block is ineffective.

Examples

class _Exception {}

Future<bool> foo() async {
  throw _Exception();
}

Future<bool> bar() async {
  try {
    print("Calling foo...");
    return /* await */ foo();
  } on _Exception catch (e) {
    print("We're all good! Exception $e is handled.");
    // ...except it's not handled at all, because of the missing `await`
    return false;
  }
}

Additional context

This problem caused the customer-affecting bug in flutterfire / cloud_functions (firebase/flutterfire#2069).

It also broke my team's app yesterday.

Metadata

Metadata

Assignees

No one assigned

    Labels

    devexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions