From 16f2e56d8e614fb07c2de978fd112a36ef620d41 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Mon, 4 Nov 2024 22:50:19 -0500 Subject: [PATCH] Handle errors from top action menu commands (#1432) --- browser_tests/menu.spec.ts | 25 +++++++++++++++++++++++++ src/stores/menuItemStore.ts | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/browser_tests/menu.spec.ts b/browser_tests/menu.spec.ts index 719e81c09..5b2f33dfa 100644 --- a/browser_tests/menu.spec.ts +++ b/browser_tests/menu.spec.ts @@ -494,6 +494,31 @@ test.describe('Menu', () => { }) expect(await exportTag.count()).toBe(1) }) + + test('Can catch error when executing command', async ({ comfyPage }) => { + await comfyPage.page.evaluate(() => { + window['app'].registerExtension({ + name: 'TestExtension1', + commands: [ + { + id: 'foo', + label: 'foo-command', + function: () => { + throw new Error('foo!') + } + } + ], + menuCommands: [ + { + path: ['ext'], + commands: ['foo'] + } + ] + }) + }) + await comfyPage.menu.topbar.triggerTopbarCommand(['ext', 'foo-command']) + expect(await comfyPage.getVisibleToastCount()).toBe(1) + }) }) // Only test 'Top' to reduce test time. diff --git a/src/stores/menuItemStore.ts b/src/stores/menuItemStore.ts index 6fdbe59e5..6d4762d1d 100644 --- a/src/stores/menuItemStore.ts +++ b/src/stores/menuItemStore.ts @@ -49,7 +49,7 @@ export const useMenuItemStore = defineStore('menuItem', () => { .map( (command) => ({ - command: command.function, + command: () => commandStore.execute(command.id), label: command.menubarLabel, icon: command.icon, tooltip: command.tooltip,