Skip to content

Commit eed77e6

Browse files
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.
1 parent b280c74 commit eed77e6

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/utils/truncate.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,15 @@ export function truncateToWidthNoEllipsis(
131131
* @param singleLine If true, also truncates at the first newline
132132
* @returns The truncated string with ellipsis if needed
133133
*/
134+
134135
export function truncate(
135136
str: string,
136137
maxWidth: number,
137138
singleLine: boolean = false,
138139
): string {
140+
// Undefined or null protection
141+
if (!str) return ''
142+
139143
let result = str
140144

141145
// If singleLine is true, truncate at first newline

0 commit comments

Comments
 (0)