-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Linter rule to prevent returning futures from the try block #62555
Copy link
Copy link
Open
Labels
P4area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
Metadata
Metadata
Assignees
Labels
P4area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packageIssues with the analyzer's support for the linter packagelinter-lint-proposaltype-enhancementA request for a change that isn't a bugA request for a change that isn't a bug
There have been multiple times when I’ve accidentally written code like this:
While the right code would look like so:
The problem can be somewhat hard to spot: we are returning a
Future<Foo>from the function instead ofawaiting it and returning the result. In the first case, the exception does not reach the catch block, causing it to be thrown outside without the intended handling. Even when the goal is only to catch and not rethrow, this remains an issue—and I can’t recall ever writing this intentionally.I thought it would be great if there were a linter rule for this, but since there isn’t, I’m submitting this feature request.