unawaited_futures and returning Future results in exceptions not caught by expected function code #58234
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-false-negative
P3
A lower priority bug or feature request
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Describe the issue
Normally, if a function returns a Future and the last statement calls a second function to obtain that Future, the
await
can be omitted. That is, there is nothing wrong with this:But when an exception can be thrown asynchronously by that second function and the first function expects to catch it, the
await
is mandatory, otherwise it will not be caught within the function.The
unawaited_futures
linter rule currently does not detect this situation.It would be good if the linter could alert the programmer that they might want to change the code to:
To Reproduce
The return statement inside the try block in the _foo_function is where the problem is.
Expected behavior
Linter warns the programmer about a potential missing await, otherwise asynchronously thrown exceptions will not be caught by the catch block(s).
Additional context
It would be good if the unawaited_futures linter rule detected this situation, since it is an example of where an await is missing for proper/expected behaviour. Triggering if the return statement is inside a try/catch block.
Or maybe it needs to be a new linter rule, since there could be interactions/complications with the unnecessary_await_in_return linter rule.
The text was updated successfully, but these errors were encountered: