-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[various] Fixes unawaited_futures violations
#4067
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
Conversation
chunhtai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for go_router and go_router_builder
| # TODO(stuartmorgan): Remove this file and fix all the unawaited_futures | ||
| # violations. See https://github.com/flutter/flutter/issues/127323 | ||
|
|
||
| include: ../../../analysis_options.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this pr. I wish we used absolute paths instead of relative paths when the absolute path has more meaning.
I know that effective dart says to prefer relative paths but in this case it matters more that we are using the root analysis_options.yaml than the one 3 folders up.
https://dart.dev/effective-dart/usage#prefer-relative-import-paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that would be better in this case, but I don't think it's actually possible; there's no package at the root.
I guess we could make a local package with the shared options, and then depend on that in every single pubspec.yaml so we could use a package: URL, but that would be pretty ugly. And the local package reference in the pubspec would have to be... a relative path.
| linter: | ||
| rules: | ||
| # Matches flutter/flutter, which disables this rule due to false positives. | ||
| unawaited_futures: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mild preference for ignore for file in the test than opting out the directory.
tarrinneal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pigeon and shared_prefs are fine, assuming ci doesn't hang on pigeon tests
ditman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why I left some of the calls sneakily unawaited, but CI will tell. 🚀
Looks like this was aspirational. Not too many failures though; I'll take a look tomorrow. |
|
|
||
| test('Injects script into desired target', () async { | ||
| loadWebSdk(target: target); | ||
| await loadWebSdk(target: target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was incorrect; the test never simulates running the callback, causing the test to hang; I'll make it unawaited with a comment.
| return (_initialization ??= _doInitialization()).catchError((dynamic _) { | ||
| // Invalidate initialization if it errors out. | ||
| _initialization = null; | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently the fact that the error wasn't being caught by the returned future was (or at least has become) intentional behavior, since there was a unit test that this change broke. I doubt very much that having _initialization not be guaranteed to be null when the future completes is intentional though, so I changed it to return the catchError wrapper, but made the wrapper rethrow after nulling _initialization.
This option had been disabled to match flutter/flutter, but the reason it was disabled there was "too many false positives", mostly around animation. That doesn't apply to most packages here, and we've had a number of production bugs—especially in plugins, that use async heavily in ways that are intended to be client-awaitable—that this would have caught.
This PR:
animationsandgo_router, both of which looked like mostly or entirely false positives.camera_android_camerax, most ofwebview_flutter).In many cases this PR is behavior-changing, replacing implicitly unawaited futures that did not seem obviously intentional with
awaited futures, so non-test code in particular should be reviewed carefully to make sure the changes are correct. All of the changes are manual, notfix-generated.Part of flutter/flutter#127323
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).