Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cubuspl42 opened this issue Sep 13, 2021 · 4 comments
Closed
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request type-enhancement A request for a change that isn't a bug

Comments

@cubuspl42
Copy link

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.

@cubuspl42 cubuspl42 added type-enhancement A request for a change that isn't a bug linter-lint-request labels Sep 13, 2021
@bwilkerson
Copy link
Member

Does the unawaited_futures lint satisfy this need?

@cubuspl42
Copy link
Author

@bwilkerson
Thank you for your suggestion.

Unfortunately, it seems that unawaited_futures doesn't work on return <expression>.

image

It would be acceptable for me that unawaited_futures was adjusted in such way, but I don't know if it would be considered a backwards-compatible change.

@stuartmorgan
Copy link
Contributor

This is a lint that we would find very valuable for flutter/packages; we've had this bug a number of times across various packages, and a lint for it would be very useful.

@srawlins
Copy link
Member

Duplicate of #58279, which has more context and discussion as well.

@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants