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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user