Add @typescript-eslint/no-floating-promises#181456
Merged
afharo merged 99 commits intoelastic:mainfrom May 1, 2024
Merged
Conversation
Member
Author
|
/ci |
20d3bd5 to
5f98831
Compare
Member
Author
|
/ci |
1 similar comment
Member
Author
|
/ci |
afharo
commented
Apr 24, 2024
Member
Author
|
/ci |
2 similar comments
Member
Author
|
/ci |
Member
Author
|
/ci |
This was referenced Apr 26, 2024
mohamedhamed-ahmed
approved these changes
Apr 30, 2024
Contributor
mohamedhamed-ahmed
left a comment
There was a problem hiding this comment.
LGTM! thanks for fixing this
pmuellr
approved these changes
May 1, 2024
Contributor
pmuellr
left a comment
There was a problem hiding this comment.
LGTM, thanks for the changes. This is going to be great!
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Canvas Sharable Runtime
History
To update your PR or re-run it, just comment with: cc @afharo |
This was referenced May 1, 2024
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable the ESLint rule
@typescript-eslint/no-floating-promises(docs). It won't allow leaving promises unhandled.Unattended promises will now require to either be
awaited,.catchor, as a very last resource if you are absolutely sure that it will never reject and want to leave it unhandled,void.For now, we've only focussed on the server-side because unhandled promises can crash the server. In the future, we might explore extending the rule to browser code.
Note to reviewers/codeowners
🛎️🚨 Please, consider creating follow-up PRs to log the caught errors, or add retries to your unattended setup/installing promises.
Identified offenders
node scripts/eslint_with_types --project examples/response_stream/tsconfig.jsonnode scripts/eslint_with_types --project examples/search_examples/tsconfig.jsonnode scripts/eslint_with_types --project src/core/tsconfig.jsonnode scripts/eslint_with_types --project src/plugins/content_management/tsconfig.jsonnode scripts/eslint_with_types --project src/plugins/data_views/tsconfig.jsonnode scripts/eslint_with_types --project src/plugins/data/tsconfig.jsonnode scripts/eslint_with_types --project src/plugins/discover/tsconfig.jsonnode scripts/eslint_with_types --project src/plugins/files/tsconfig.jsonnode scripts/eslint_with_types --project src/plugins/kibana_usage_collection/tsconfig.jsonnode scripts/eslint_with_types --project src/plugins/maps_ems/tsconfig.jsonnode scripts/eslint_with_types --project src/plugins/navigation/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/packages/ml/response_stream/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/actions/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/aiops/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/asset_manager/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/cloud_defend/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/alerting/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/canvas/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/ecs_data_quality_dashboard/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/cases/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/cross_cluster_replication/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/cloud_security_posture/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/elastic_assistant/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/event_log/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/file_upload/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/license_api_guard/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/license_management/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/lists/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/notifications/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/maps/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/fleet/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/enterprise_search/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/monitoring/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/ml/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/apm_data_access/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/logs_shared/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/observability_ai_assistant/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/apm/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/infra/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/observability/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/profiling/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/slo/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/uptime/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/observability_solution/synthetics/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/rule_registry/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/reporting/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/osquery/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/screenshotting/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/search_notebooks/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/search_playground/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/security/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/serverless_search/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/security_solution_serverless/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/spaces/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/task_manager/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/stack_alerts/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/timelines/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/threat_intelligence/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/stack_connectors/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/upgrade_assistant/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/test/functional_cors/plugins/kibana_cors_test/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/transform/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/triggers_actions_ui/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/test/plugin_api_perf/plugins/task_manager_performance/tsconfig.jsonnode scripts/eslint_with_types --project x-pack/plugins/security_solution/tsconfig.jsonTypical use cases found
Jest tests not awaiting
expect(promise).resolvesandexpect(promise).rejectsassertionsIf not awaited, jest just finishes the test without validating the assertion. Proof of that #181847
Unattended cleanups
Cleaning up PIT (point-in-time) search finders or task-manager tasks is important, although, sometimes, we don't want to hold the main business logic while doing that. We're using unattended promises in those scenarios. And that's fine! As long as those promises are caught.
Setup async operations
Kibana architecture does not allow plugins to use async lifecycle methods. This means that a plugin creating an index during setup/start can't await the promise, and they are sometimes left unattended.
We need to make sure that we catch those promises and either log the errors or attempt retries (if the setup really needs to happen).
core.getStartServices()Holding some setup methods until it can access the
startcontracts.In general, you should reconsider your approach to a getter-based mode:
If you can't, you can consider either using
voidor, if you think your code inside the.thenmight fail due to side effects, then make sure to add a.catchat the end.Loops not returning the promise
This looks like an easy to miss overlook: looping to an array, and creating promises, but not awaiting them.
Doing this:
Instead of this:
Or this:
try-catching a non-awaited promise
Some other cases, we correctly try-catch the promise, but forget to await it. This means the try-catch will only catch synchronous errors.
Instead of this:
Do this:
Risk Matrix
eslint-disableor simply addingvoidin front of the promiseFor maintainers