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.
This commit is contained in:
Amir Hardon
2025-05-08 20:56:46 -07:00
committed by N. Taylor Mullen
parent 74cc554ac4
commit 390747cc8c
3 changed files with 92 additions and 20 deletions
+14 -6
View File
@@ -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