From 1c486a40501baf7ab675383efe23c36508a9f24c Mon Sep 17 00:00:00 2001
From: Amir Hardon <amirha@google.com>
Date: Thu, 8 May 2025 20:56:46 -0700
Subject: Fix: Prevent CLI from crashing when a configured theme is not found

Previously, if a theme specified in the user's settings was not found, the CLI would crash during startup. This was particularly affecting users upgrading from older versions as the "ANSI colors only" theme was renamed to "ANSI".

This commit adds error handling to catch the theme not found error during initial loading and when setting themes later. Instead of crashing, the application now logs a warning, displays an error message in the UI, and opens the theme selection dialog to allow the user to choose a valid theme.
---
 packages/cli/src/ui/App.tsx | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

(limited to 'packages/cli/src/ui/App.tsx')

diff --git a/packages/cli/src/ui/App.tsx b/packages/cli/src/ui/App.tsx
index 9fe651b5..725a2012 100644
--- a/packages/cli/src/ui/App.tsx
+++ b/packages/cli/src/ui/App.tsx
@@ -39,12 +39,13 @@ export const App = ({ config, settings, cliVersion }: AppProps) => {
   const { history, addItem, clearItems } = useHistory();
   const [startupWarnings, setStartupWarnings] = useState<string[]>([]);
   const [showHelp, setShowHelp] = useState<boolean>(false);
+  const [themeError, setThemeError] = useState<string | null>(null);
   const {
     isThemeDialogOpen,
     openThemeDialog,
     handleThemeSelect,
     handleThemeHighlight,
-  } = useThemeCommand(settings);
+  } = useThemeCommand(settings, setThemeError);
 
   const [staticKey, setStaticKey] = useState(0);
   const refreshStatic = useCallback(() => {
@@ -191,11 +192,18 @@ export const App = ({ config, settings, cliVersion }: AppProps) => {
       )}
 
       {isThemeDialogOpen ? (
-        <ThemeDialog
-          onSelect={handleThemeSelect}
-          onHighlight={handleThemeHighlight}
-          settings={settings}
-        />
+        <Box flexDirection="column">
+          {themeError && (
+            <Box marginBottom={1}>
+              <Text color={Colors.AccentRed}>{themeError}</Text>
+            </Box>
+          )}
+          <ThemeDialog
+            onSelect={handleThemeSelect}
+            onHighlight={handleThemeHighlight}
+            settings={settings}
+          />
+        </Box>
       ) : (
         <>
           <LoadingIndicator
-- 
cgit v1.2.3

