From eed77e6579866a98384dcc948a0ad6406614ede3 Mon Sep 17 00:00:00 2001 From: Andrei Parshin Date: Thu, 16 Apr 2026 23:57:40 -0600 Subject: [PATCH] fix: prevent crash in commands tab when description is undefined (#730) This commit fixes a crash in the CLI that occurs when navigating to the /help commands tab. The issue happens because the truncate function receives an undefined value for the str parameter if a command lacks a description, causing the .indexOf() method to throw an exception. To resolve this, an early return check was added at the beginning of the function to gracefully handle empty values and prevent the UI from crashing. --- src/utils/truncate.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/truncate.ts b/src/utils/truncate.ts index fa35c10e..c0a1d716 100644 --- a/src/utils/truncate.ts +++ b/src/utils/truncate.ts @@ -131,11 +131,15 @@ export function truncateToWidthNoEllipsis( * @param singleLine If true, also truncates at the first newline * @returns The truncated string with ellipsis if needed */ + export function truncate( str: string, maxWidth: number, singleLine: boolean = false, ): string { + // Undefined or null protection + if (!str) return '' + let result = str // If singleLine is true, truncate at first newline