gitbutlerapp/gitbutler · error · anyhow::Error
Unknown theme preset: {unknown}
Error message
Unknown theme preset: {unknown} What it means
ThemePreset::from_str normalizes case and surrounding whitespace but accepts only the exact values 'dark' and 'light'. Any other string supplied via theme config or a CLI flag fails this parse error.
Source
Thrown at crates/but/src/theme.rs:234
/// Identifiers for the theme presets.
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ThemePreset {
/// The dark preset.
Dark,
/// The light preset.
Light,
}
impl FromStr for ThemePreset {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let normalized = s.to_lowercase();
match normalized.trim() {
"dark" => Ok(ThemePreset::Dark),
"light" => Ok(ThemePreset::Light),
unknown => Err(anyhow::anyhow!("Unknown theme preset: {unknown}")),
}
}
}
/// Detect the theme preset from the terminal's foreground and background colors.
///
/// Returns `None` if the terminal does not support color queries or does not respond in time.
pub(crate) fn detect_terminal_preset() -> Option<ThemePreset> {
terminal_colorsaurus::theme_mode(terminal_colorsaurus::QueryOptions::default())
.ok()
.map(theme_preset_from_terminal_mode)
}
fn theme_preset_from_terminal_mode(mode: terminal_colorsaurus::ThemeMode) -> ThemePreset {
match mode {
terminal_colorsaurus::ThemeMode::Dark => ThemePreset::Dark,
terminal_colorsaurus::ThemeMode::Light => ThemePreset::Light,
}View on GitHub (pinned to caf1f223d3)
Solutions
- Use 'dark' or 'light' (case-insensitive)
- Omit the setting so but falls back to detecting the terminal theme (detect_terminal_preset)
- Check the config file for typos, quotes, or trailing whitespace around the value
Example fix
# before theme = "auto" # not a valid preset # after theme = "dark" # or "light", or remove the key for auto-detection
Defensive patterns
Strategy: validation
Validate before calling
fn is_theme_preset(s: &str) -> bool {
matches!(s.trim().to_lowercase().as_str(), "dark" | "light")
} Type guard
fn theme_preset_or_none(s: &str) -> Option<ThemePreset> {
match s.trim().to_lowercase().as_str() {
"dark" => Some(ThemePreset::Dark),
"light" => Some(ThemePreset::Light),
_ => None,
}
} Prevention
- Validate theme values against the enum before writing config
- Fall back to detect_terminal_preset() on unknown values instead of failing
When it happens
Trigger: Setting the theme preset to anything other than dark/light, such as 'auto', 'system', 'terminal', or 'high-contrast', in the config file or on the command line.
Common situations: Users expecting 'auto'/'system' to trigger terminal color detection; configs copied from other tools with different vocabulary; stray whitespace or quotes around the value.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Failed to parse diff header
- BUG: It should not be possible to omit sources
- implement list and call recursively
- Refusing to install symlink onto existing non-symlink at '{U
- Run `CARGO_TARGET_DIR=$PWD/target/tauri cargo build -p but`
AI-assisted analysis of gitbutlerapp/gitbutler@caf1f223d3 (2026-08-20).
Data as JSON: /api/errors/16fa1ce0d02c0a0a.
Report an issue: GitHub.