From 94bb900d723d0d937dffb22a7decc9cde12e9132 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 20 Nov 2024 16:55:51 +1100 Subject: [PATCH] [8.x] [uiActions] Catch errors in isCompatible (#200261) (#200839) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.x`: - [[uiActions] Catch errors in isCompatible (#200261)](https://github.com/elastic/kibana/pull/200261) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Catherine Liu --- .../ui_actions/public/actions/action_internal.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins/ui_actions/public/actions/action_internal.ts b/src/plugins/ui_actions/public/actions/action_internal.ts index ccef920ecc465..6f979849bdc41 100644 --- a/src/plugins/ui_actions/public/actions/action_internal.ts +++ b/src/plugins/ui_actions/public/actions/action_internal.ts @@ -29,6 +29,7 @@ export class ActionInternal public readonly subscribeToCompatibilityChanges?: Action['subscribeToCompatibilityChanges']; public readonly couldBecomeCompatible?: Action['couldBecomeCompatible']; + public errorLogged?: boolean; constructor(public readonly definition: ActionDefinition) { this.id = this.definition.id; @@ -38,6 +39,7 @@ export class ActionInternal 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; @@ -77,7 +79,16 @@ export class ActionInternal public async isCompatible(context: Context): Promise { 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 {