Skip to content

Commit

Permalink
[8.x] [uiActions] Catch errors in isCompatible (#200261) (#200839)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[uiActions] Catch errors in isCompatible
(#200261)](#200261)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Catherine
Liu","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-20T04:08:48Z","message":"[uiActions]
Catch errors in isCompatible (#200261)\n\n## Summary\r\n\r\nRelated to
https://github.com/elastic/kibana/issues/197870.\r\n\r\nThe bug reported
in #197870 was a side effect of unhandled errors in
the\r\n`isCompatible` check on the edit drilldown `uiAction`. When
errors are\r\nthrow in the `isCompatible` check on an `Action`, we
should return\r\n`false` instead of throwing to unblock the rest of the
compatibility\r\nchecks.\r\n\r\n<img width=\"1800\" alt=\"Screenshot
2024-11-14 at 3 30
20 PM\"\r\nsrc=\"https://github.com/user-attachments/assets/6189c2dc-2a9d-4c81-be1e-b5f94ba43123\">\r\n\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_node:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Identify risks\r\n\r\nDoes this PR introduce any risks? For example,
consider risks like hard\r\nto test bugs, performance regression,
potential of data loss.\r\n\r\nDescribe the risk, its severity, and
mitigation for each identified\r\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\r\n\r\n- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ]
...","sha":"d697a67a05325ae71384e6f1c26235fce4924005","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Presentation","loe:small","release_note:skip","impact:medium","Feature:UIActions","v9.0.0","Team:SharedUX","backport:version","v8.17.0"],"title":"[uiActions]
Catch errors in
isCompatible","number":200261,"url":"https://github.com/elastic/kibana/pull/200261","mergeCommit":{"message":"[uiActions]
Catch errors in isCompatible (#200261)\n\n## Summary\r\n\r\nRelated to
https://github.com/elastic/kibana/issues/197870.\r\n\r\nThe bug reported
in #197870 was a side effect of unhandled errors in
the\r\n`isCompatible` check on the edit drilldown `uiAction`. When
errors are\r\nthrow in the `isCompatible` check on an `Action`, we
should return\r\n`false` instead of throwing to unblock the rest of the
compatibility\r\nchecks.\r\n\r\n<img width=\"1800\" alt=\"Screenshot
2024-11-14 at 3 30
20 PM\"\r\nsrc=\"https://github.com/user-attachments/assets/6189c2dc-2a9d-4c81-be1e-b5f94ba43123\">\r\n\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_node:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Identify risks\r\n\r\nDoes this PR introduce any risks? For example,
consider risks like hard\r\nto test bugs, performance regression,
potential of data loss.\r\n\r\nDescribe the risk, its severity, and
mitigation for each identified\r\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\r\n\r\n- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ]
...","sha":"d697a67a05325ae71384e6f1c26235fce4924005"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200261","number":200261,"mergeCommit":{"message":"[uiActions]
Catch errors in isCompatible (#200261)\n\n## Summary\r\n\r\nRelated to
https://github.com/elastic/kibana/issues/197870.\r\n\r\nThe bug reported
in #197870 was a side effect of unhandled errors in
the\r\n`isCompatible` check on the edit drilldown `uiAction`. When
errors are\r\nthrow in the `isCompatible` check on an `Action`, we
should return\r\n`false` instead of throwing to unblock the rest of the
compatibility\r\nchecks.\r\n\r\n<img width=\"1800\" alt=\"Screenshot
2024-11-14 at 3 30
20 PM\"\r\nsrc=\"https://github.com/user-attachments/assets/6189c2dc-2a9d-4c81-be1e-b5f94ba43123\">\r\n\r\n\r\n###
Checklist\r\n\r\nCheck the PR satisfies following conditions.
\r\n\r\nReviewers should verify this PR satisfies this list as
well.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_node:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Identify risks\r\n\r\nDoes this PR introduce any risks? For example,
consider risks like hard\r\nto test bugs, performance regression,
potential of data loss.\r\n\r\nDescribe the risk, its severity, and
mitigation for each identified\r\nrisk. Invite stakeholders and evaluate
how to proceed before merging.\r\n\r\n- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ]
...","sha":"d697a67a05325ae71384e6f1c26235fce4924005"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Catherine Liu <[email protected]>
  • Loading branch information
kibanamachine and cqliu1 authored Nov 20, 2024
1 parent 33670f5 commit 94bb900
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/plugins/ui_actions/public/actions/action_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class ActionInternal<Context extends object = object>

public readonly subscribeToCompatibilityChanges?: Action<Context>['subscribeToCompatibilityChanges'];
public readonly couldBecomeCompatible?: Action<Context>['couldBecomeCompatible'];
public errorLogged?: boolean;

constructor(public readonly definition: ActionDefinition<Context>) {
this.id = this.definition.id;
Expand All @@ -38,6 +39,7 @@ export class ActionInternal<Context extends object = object>
this.grouping = this.definition.grouping;
this.showNotification = this.definition.showNotification;
this.disabled = this.definition.disabled;
this.errorLogged = false;

if (this.definition.subscribeToCompatibilityChanges) {
this.subscribeToCompatibilityChanges = definition.subscribeToCompatibilityChanges;
Expand Down Expand Up @@ -77,7 +79,16 @@ export class ActionInternal<Context extends object = object>

public async isCompatible(context: Context): Promise<boolean> {
if (!this.definition.isCompatible) return true;
return await this.definition.isCompatible(context);
try {
return await this.definition.isCompatible(context);
} catch (e) {
if (!this.errorLogged) {
// eslint-disable-next-line no-console
console.error(e);
this.errorLogged = true;
}
return false;
}
}

public async getHref(context: Context): Promise<string | undefined> {
Expand Down

0 comments on commit 94bb900

Please sign in to comment.