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.
This commit is contained in:
Taylor Mullen
2025-05-09 10:20:08 -07:00
committed by N. Taylor Mullen
parent c58f879026
commit b8fa38a6e8
3 changed files with 23 additions and 59 deletions

View File

@@ -73,14 +73,23 @@ class ThemeManager {
/**
* Sets the active theme.
* @param themeName The name of the theme to activate.
* @returns True if the theme was successfully set, false otherwise.
*/
setActiveTheme(themeName: string | undefined): void {
setActiveTheme(themeName: string | undefined): boolean {
const foundTheme = this.findThemeByName(themeName);
if (foundTheme) {
this.activeTheme = foundTheme;
return true;
} else {
throw new Error(`Theme "${themeName}" not found.`);
// If themeName is undefined, it means we want to set the default theme.
// If findThemeByName returns undefined (e.g. default theme is also not found for some reason)
// then this will return false.
if (themeName === undefined) {
this.activeTheme = DEFAULT_THEME;
return true;
}
return false;
}
}