diff options
| author | Taylor Mullen <[email protected]> | 2025-05-09 10:20:08 -0700 |
|---|---|---|
| committer | N. Taylor Mullen <[email protected]> | 2025-05-09 10:28:20 -0700 |
| commit | b8fa38a6e8f60acf6489fde545a91d3ba4c395d7 (patch) | |
| tree | 9f5950e4bf5c644a9890786a43243e2859ad3642 /packages/cli/src/ui/hooks/useThemeCommand.ts | |
| parent | c58f8790265fc80b52dbba1127f2c2e5b90ef737 (diff) | |
feat: Improve theme not found handling
Modify to return a boolean instead of throwing an error when a theme is not found. Update CLI startup and hook to handle the boolean return value for more graceful error handling.
Diffstat (limited to 'packages/cli/src/ui/hooks/useThemeCommand.ts')
| -rw-r--r-- | packages/cli/src/ui/hooks/useThemeCommand.ts | 52 |
1 files changed, 10 insertions, 42 deletions
diff --git a/packages/cli/src/ui/hooks/useThemeCommand.ts b/packages/cli/src/ui/hooks/useThemeCommand.ts index b1ae170f..d8b0ef6b 100644 --- a/packages/cli/src/ui/hooks/useThemeCommand.ts +++ b/packages/cli/src/ui/hooks/useThemeCommand.ts @@ -32,28 +32,12 @@ export const useThemeCommand = ( // Apply initial theme on component mount useEffect(() => { - try { - themeManager.setActiveTheme(effectiveTheme); - setThemeError(null); // Clear any previous theme error on success - } catch (error: unknown) { + if (!themeManager.setActiveTheme(effectiveTheme)) { // If theme is not found during initial load, open the theme selection dialog and set error message - if ( - error instanceof Error && - error.message.includes('Theme') && - error.message.includes('not found') - ) { - setIsThemeDialogOpen(true); - setThemeError( - `Error: ${error instanceof Error ? error.message : String(error)}`, - ); - } else { - console.error( - `Error setting initial theme: ${error instanceof Error ? error.message : String(error)}`, - ); - setThemeError( - `Error setting initial theme: ${error instanceof Error ? error.message : String(error)}`, - ); - } + setIsThemeDialogOpen(true); + setThemeError(`Theme "${effectiveTheme}" not found.`); + } else { + setThemeError(null); // Clear any previous theme error on success } }, [effectiveTheme, setThemeError]); // Re-run if effectiveTheme or setThemeError changes @@ -63,29 +47,13 @@ export const useThemeCommand = ( const applyTheme = useCallback( (themeName: string | undefined) => { - try { - themeManager.setActiveTheme(themeName); + if (!themeManager.setActiveTheme(themeName)) { + // If theme is not found, open the theme selection dialog and set error message + setIsThemeDialogOpen(true); + setThemeError(`Theme "${themeName}" not found.`); + } else { setForceRender((v) => v + 1); // Trigger potential re-render setThemeError(null); // Clear any previous theme error on success - } catch (error: unknown) { - // If theme is not found, open the theme selection dialog and set error message - if ( - error instanceof Error && - error.message.includes('Theme') && - error.message.includes('not found') - ) { - setIsThemeDialogOpen(true); - setThemeError( - `Error: ${error instanceof Error ? error.message : String(error)}`, - ); - } else { - console.error( - `Error setting theme: ${error instanceof Error ? error.message : String(error)}`, - ); - setThemeError( - `Error setting theme: ${error instanceof Error ? error.message : String(error)}`, - ); - } } }, [setForceRender, setThemeError], |
