{"record":{"id":"44838dc8270bed8a","repo":"musistudio/claude-code-router","slug":"invalid-theme-preference","errorCode":null,"errorMessage":"Invalid theme preference.","messagePattern":"Invalid theme preference\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/config/config.ts","lineNumber":411,"sourceCode":"  const normalizedConfig = withSingleEnabledGlobalProfiles(config);\n  assertProviderApiKeysAreSafe(normalizedConfig);\n  const apiKeys = ensureGatewayApiKeys(normalizeApiKeys(normalizedConfig.APIKEYS, normalizedConfig.APIKEY).filter((apiKey) => !isDefaultSeedApiKey(apiKey)));\n  const pluginMigration = migrateKnownGatewayPluginConfigs(normalizedConfig.plugins);\n  await replacePersistedConfigSnapshot(sanitizeConfigForDisk({\n    ...normalizedConfig,\n    theme: appThemePreferenceOverride ?? normalizedConfig.theme,\n    APIKEY: apiKeys[0]?.key ?? \"\",\n    APIKEYS: apiKeys,\n    plugins: pluginMigration.plugins\n  }), apiKeys);\n  return loadAppConfig();\n}\n\nfunction normalizeAppThemePreference(theme: unknown): AppConfig[\"theme\"] {\n  if (theme === \"system\" || theme === \"light\" || theme === \"dark\") {\n    return theme;\n  }\n  throw new Error(\"Invalid theme preference.\");\n}\n\nfunction enqueueAppConfigWrite<T>(operation: () => Promise<T>): Promise<T> {\n  const result = appConfigWriteQueue.then(operation, operation);\n  appConfigWriteQueue = result.then(\n    () => undefined,\n    () => undefined\n  );\n  return result;\n}\n\nfunction withSingleEnabledGlobalProfiles(config: AppConfig): AppConfig {\n  const profiles = enforceSingleEnabledGlobalProfilePerAgent(config.profile.profiles);\n  return {\n    ...config,\n    Providers: config.Providers.map(normalizeProviderPresetCapabilities),\n    profile: synchronizeLegacyProfileConfig({\n      ...config.profile,","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/core/src/config/config.ts#L393-L429","documentation":"normalizeAppThemePreference only accepts the literal strings 'system', 'light', or 'dark'; any other value (including undefined/null/numbers) throws when normalizing app config.","triggerScenarios":"Loading/saving app config where theme is not one of the three accepted literals — e.g. hand-edited config file, config written by an older/newer version, or a UI writing a raw enum.","commonSituations":"User edits config.json and types \"Dark\" or \"auto\"; migration writes theme: null.","solutions":["Set theme to \"system\", \"light\", or \"dark\" in the config file.","Sanitize before saving: coerce unknown values to \"system\".","Re-save config from the app's settings UI to rewrite a valid value."],"exampleFix":"// before\ntheme: config.theme // may be \"Dark\"\n// after\ntheme: [\"system\",\"light\",\"dark\"].includes(config.theme) ? config.theme : \"system\"","handlingStrategy":"type-guard","validationCode":"if (!['system','light','dark'].includes(cfg.theme)) cfg.theme = 'system';","typeGuard":"function isAppTheme(v: unknown): v is 'system' | 'light' | 'dark' {\n  return v === 'system' || v === 'light' || v === 'dark';\n}","tryCatchPattern":"catch (e) { if ((e as Error).message === 'Invalid theme preference.') { config.theme = 'system'; await save(config); } }","preventionTips":["Validate hand-edited configs before load.","Write themes only from the settings UI."],"tags":["config","theme","validation"],"backgroundTag":"enum-validation-failed","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}