Skip to content

Commit 00ed79e

Browse files
committed
fix(gui): prevent TypeError in extension command registration and notification handling
- Add optional chaining for ext.manifest?.name with fallback to 'Unknown' - Add null check for event.payload before destructuring - Prevent 'Cannot read properties of undefined' errors in event handlers AGENT1: Core & App Shell analysis and fixes
1 parent 063a09d commit 00ed79e

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

cortex-gui/src/App.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function ExtensionCommandRegistrar(): null {
174174
(ext.manifest?.contributes?.commands || []).map(contrib => ({
175175
id: contrib.command,
176176
label: contrib.title,
177-
category: contrib.category || ext.manifest.name,
177+
category: contrib.category || ext.manifest?.name || 'Unknown',
178178
action: () => extensions.executeExtensionCommand(contrib.command)
179179
}))
180180
);
@@ -198,7 +198,9 @@ function ExtensionNotificationListener(): null {
198198

199199
onMount(async () => {
200200
unlisten = await listen("extension:notification", (event: any) => {
201-
const { type, message } = event.payload;
201+
const payload = event?.payload;
202+
if (!payload) return;
203+
const { type, message } = payload;
202204
if (type === "info") toast.info(message);
203205
else if (type === "error") toast.error(message);
204206
});

cortex-gui/src/AppCore.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function ExtensionCommandRegistrar(): null {
177177
(ext.manifest?.contributes?.commands || []).map(contrib => ({
178178
id: contrib.command,
179179
label: contrib.title,
180-
category: contrib.category || ext.manifest.name,
180+
category: contrib.category || ext.manifest?.name || 'Unknown',
181181
action: () => extensions.executeExtensionCommand(contrib.command)
182182
}))
183183
);
@@ -201,7 +201,9 @@ function ExtensionNotificationListener(): null {
201201

202202
onMount(async () => {
203203
unlisten = await listen("extension:notification", (event: any) => {
204-
const { type, message } = event.payload;
204+
const payload = event?.payload;
205+
if (!payload) return;
206+
const { type, message } = payload;
205207
if (type === "info") toast.info(message);
206208
else if (type === "error") toast.error(message);
207209
});

0 commit comments

Comments
 (0)