-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Spurious unawaited_futures
warnings
#57437
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
Comments
@alexeieleusis : any thoughts? |
That's a change in the |
In the short term, it might make sense to special-case |
I don't have enough context on this rule, I've seen a few places where even though you are in an async method body you don't want to await, but probably is worth ignoring with a comment. @ochafik who originally wrote the rule should have more context on the use cases for this. It would be nice to also have feedback from a readability team member. |
Shouldn't that rule also fire in non-async context when a future is returned that is not chained with |
Wouldn't the new |
@zoechi That seems like a hack, although one that may work in the short term. There's no reason in principle that Also, it will hurt inference for cases (like |
FYI, this lint, were it enabled in Flutter, would have saved me about ~4 hours of debugging today. |
@nex3 is that really different to the annotation you (AFAIR) suggested, to annotate a method to indicate whether or not it should be awaited? (just from what I remember because I wasn't able to find the issue). |
The reason for the current behaviour of this lint is to not forget to await when "in an async state of mind" (i.e. inside an async method), while allowing people to fire-and-forget. This does leave out code that forgot to use an async method at the first place, but we've found countless bugs in our codebase with this linter already. Re/ spurious warnings: one can disable this warning, not use an async method, or wrap the fire-and-forget call in a local void-returning non-async helper. |
Yes;
None of these seem to be satisfactory for users of this lint using @pq Can we prioritize this? It's blocking the Google3 roll of |
It's not clear to me that the right fix isn't to roll back dart-lang/test#529. |
@nex3 :
Are you suggesting specifically we special-case That said,
I'm wondering about this too. What about rolling back and the regrouping? If the API change sticks we can talk about how to coordinate to soften the transition... |
We can't "roll back" a released package, and lints can't render an API change invalid anyway. The linter's role is to help people work with real-world code, not to put constraints on what code can exist. There's no way for API designers to know when a change might break one of the many (sometimes contradictory) lints that exist, so the lints that are sensitive to those changes need to be able to react quickly when they happen.
As I mentioned above, I think the best solution here would be to provide an |
Why do we need to add yet-another annotation because I'm still holding out for |
If we consider any API change "breaking" if it causes optional potentially-contradictory lints to produce new warnings, then it becomes next to impossible for authors to know whether or not their changes are "breaking". It also puts egregious constraints on otherwise reasonable and useful API patterns. It's not a tenable restriction. We must instead work to make lints that can be affected by upstream APIs more flexible.
I don't think user referenda are a road to good design under any circumstances, but I strongly stand behind my API for reasons I've gone over in detail elsewhere. |
I don't think it's about API changes not to be allowed to break lints. I still find introducing an
You can just release another update with the changes removed. That wouldn't cause much harm considering how recent the previous release was published. |
I might miss some context, but I think the best way to go is to just special-case |
@nex3 's change landed in dart-lang/test#546. I think we're on our way to closing this... @tvolkert: can we bump Flutter to |
It's not clear to me if it's currently possible to disable a lint with an |
It is supported, intellij has a keyboard shortcut for it Alt+Enter
|
@ochafik : totally possible. Lints (like all errors) can be suppressed per-line. https://www.dartlang.org/guides/language/analysis-options#excluding-lines-within-a-file |
Please re-open this—we still need a way to mark methods that return futures as not needing |
Thanks! |
@nex3 it seems like more modern constructs of the Dart SDK that didn't exist 15 months ago make this problem easily solvable now -- and obviate the need for FutureOr<void> expect(...); Then, callers could await if they needed to, but the linter wouldn't force them to. Thoughts? |
It seems like the idea of whether a given future should always be awaited should be orthogonal to the type of that future. Also, |
Is this still a problem? I haven't noticed any problems with using |
tl;dr Summary at the end rd;lt @nex3 wrote:
That part has been resolved: A function can have the void fireAndForget() async {
...
} and that combination is specifically allowed in order to support the scenario where the caller should not await the returned future (that is, fire-and-forget by design, not by accident). The lint avoid_void_async tries to get rid of these functions entirely (and I agree that they are quite likely to arise by accident, e.g., when someone adds Concerning the return type of The type If you want to say that a function may return a An With that, it would make sense to think carefully about lints on values of type This covers I think the summary would then be:
So if we keep this issue open it should probably focus on that third bullet: How to treat values of type |
This doesn't resolve the original issue. The original issue is to be able to design an API that may be awaited, but to express that it is safe to not await it. A return type of That said, I'm only personally aware of 2 use cases and both have been just fine as is.
The metadata was the current focus of this thread. IMO |
@natebosch responded to (
Right, I mentioned it because this issue was reopened specifically in order to address that particular need. However, the other part remains:
Agreed, and thanks for making that point more forcefully than I did. I wasn't sure, and said that we'd need to 'think carefully', but at this point I agree that it's not a good use of that type. The robust way to express that it's safe to not await a function result would be to use metadata (like OTOH, |
* Disable comment_references. What it considers as in-scope identifiers does not match reality, and it generates a lot of false positive errors. * Disable type_annotate_public_apis. It's too annoying for cases with obvious types (e.g. `final foo = Type();`). * Enable unawaited_futures. I'm not sure if https://github.com/dart-lang/linter/issues/419 is still relevant; I haven't noticed any problems. PiperOrigin-RevId: 272701433
* Disable comment_references. What it considers as in-scope identifiers does not match reality, and it generates a lot of false positive errors. * Disable type_annotate_public_apis. It's too annoying for cases with obvious types (e.g. `final foo = Type();`). * Enable unawaited_futures. I'm not sure if https://github.com/dart-lang/linter/issues/419 is still relevant; I haven't noticed any problems. PiperOrigin-RevId: 272701433
* Disable comment_references. What it considers as in-scope identifiers does not match reality, and it generates a lot of false positive errors. * Disable type_annotate_public_apis. It's too annoying for cases with obvious types (e.g. `final foo = Type();`). * Enable unawaited_futures. I'm not sure if https://github.com/dart-lang/linter/issues/419 is still relevant; I haven't noticed any problems. PiperOrigin-RevId: 272701433
Steps to Reproduce
git clone [email protected]:google/file.dart.git
cd file.dart
dartanalyzer .
Expected Results
No analyzer warnings. At least, until very recently, there were no warnings.
Actual Results
https://gist.github.com/tvolkert/4ae91439e738207d3b566e758e7b7680
What's very strange is that many of the lines it complains about don't even have futures at all, like https://github.com/google/file.dart/blob/master/test/replay_test.dart#L57. Other lines do have futures and are of the form
expect(futureValue, throwsFoo)
, which have never produced any lint warnings before.The text was updated successfully, but these errors were encountered: