From 5832170b2b80dae03906adc8f10c161f30e57e93 Mon Sep 17 00:00:00 2001 From: Laurent Nguyen Date: Fri, 20 Feb 2026 16:42:17 +0100 Subject: [PATCH] Fix extractHeaderStatus to handle undefined and non-string messages (#2393) * Fix extractHeaderStatus to handle undefined and non-string messages * Fix unsafe casts --------- Co-authored-by: Laurent Nguyen --- src/Explorer/DataSamples/ContainerSampleGenerator.ts | 2 +- .../NotificationConsole/NotificationConsoleComponent.tsx | 5 ++++- src/Platform/Fabric/FabricUtil.ts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Explorer/DataSamples/ContainerSampleGenerator.ts b/src/Explorer/DataSamples/ContainerSampleGenerator.ts index 7613b7a07..8d65c1fb0 100644 --- a/src/Explorer/DataSamples/ContainerSampleGenerator.ts +++ b/src/Explorer/DataSamples/ContainerSampleGenerator.ts @@ -113,7 +113,7 @@ export class ContainerSampleGenerator { ? await createMongoDocument(collection.databaseId, collection, shardKey, doc) : await createDocument(collection, doc); } catch (error) { - NotificationConsoleUtils.logConsoleError(error); + NotificationConsoleUtils.logConsoleError(error instanceof Error ? error.message : String(error)); } }), ); diff --git a/src/Explorer/Menus/NotificationConsole/NotificationConsoleComponent.tsx b/src/Explorer/Menus/NotificationConsole/NotificationConsoleComponent.tsx index 98cc63758..423be1198 100644 --- a/src/Explorer/Menus/NotificationConsole/NotificationConsoleComponent.tsx +++ b/src/Explorer/Menus/NotificationConsole/NotificationConsoleComponent.tsx @@ -329,7 +329,10 @@ export class NotificationConsoleComponent extends React.Component< } private static extractHeaderStatus(consoleData: ConsoleData) { - return consoleData?.message.split(":\n")[0]; + if (!consoleData?.message || typeof consoleData.message !== "string") { + return undefined; + } + return consoleData.message.split(":\n")[0]; } private onConsoleWasExpanded = (): void => { diff --git a/src/Platform/Fabric/FabricUtil.ts b/src/Platform/Fabric/FabricUtil.ts index 52e3a645d..b6a83644b 100644 --- a/src/Platform/Fabric/FabricUtil.ts +++ b/src/Platform/Fabric/FabricUtil.ts @@ -37,7 +37,7 @@ const requestFabricToken = async (): Promise => { scheduleRefreshFabricToken(); } catch (error) { - logConsoleError(error as string); + logConsoleError(error instanceof Error ? error.message : String(error)); throw error; } finally { lastRequestTimestamp = undefined;