From 7bf403356acec0753d755a384c7633d7ecce528f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 6 Feb 2024 19:08:05 -0500 Subject: [PATCH] fix: Unseen error on client action execution --- app/actions/index.ts | 12 +++++++++--- app/types.ts | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/actions/index.ts b/app/actions/index.ts index 168a37ab4..7ad340b00 100644 --- a/app/actions/index.ts +++ b/app/actions/index.ts @@ -119,7 +119,13 @@ export function actionToKBar( } export async function performAction(action: Action, context: ActionContext) { - return action.perform?.(context)?.catch((err: Error) => { - toast.error(err.message); - }); + const result = action.perform?.(context); + + if (result instanceof Promise) { + return result.catch((err: Error) => { + toast.error(err.message); + }); + } + + return result; } diff --git a/app/types.ts b/app/types.ts index 74b7d9514..afd95a5bd 100644 --- a/app/types.ts +++ b/app/types.ts @@ -111,7 +111,7 @@ export type Action = { * Perform the action – note this should generally not be called directly, use `performAction` * instead. Errors will be caught and displayed to the user as a toast message. */ - perform?: (context: ActionContext) => Promise | any; + perform?: (context: ActionContext) => any; children?: ((context: ActionContext) => Action[]) | Action[]; };