libnyanpasu/clash-nyanpasu · error

Invalid theme color: {}

Error message

Invalid theme color: {}

What it means

Validation guard in validate_verge_patch rejecting a verge patch whose theme_color is set, non-empty, and not a valid hex color per legacy_app::is_hex_color. The faulting input is the user-supplied theme_color string inside the IVerge patch; the patch is aborted before any config is applied, so an invalid value never reaches persisted state.

Source

Thrown at backend/tauri/src/bridge/verge.rs:502

fn validate_verge_patch(verge: &IVerge) -> anyhow::Result<()> {
    if let Some(theme_color) = &verge.theme_color
        && !theme_color.is_empty()
        && !legacy_app::is_hex_color(theme_color)
    {
        anyhow::bail!("Invalid theme color: {}", theme_color);
    }
    Ok(())
}

View on GitHub (pinned to f7dbce2997)

Solutions

  1. Convert the value to a hex color string like '#55008f' before patching
  2. Clear theme_color (empty string is allowed) to use the default
  3. Add client-side validation that checks hex format before submitting the patch

Example fix

// before
patch.theme_color = 'rgb(85,0,143)'
// after
patch.theme_color = '#55008f'
Defensive patterns

Strategy: validation

Validate before calling

const isHexColor = (s: string) => /^#[0-9a-fA-F]{6}$/.test(s)
if (patch.theme_color && !isHexColor(patch.theme_color)) {
  throw new Error('theme_color must be a hex color like #55008f')
}

Type guard

const isHexColor = (v: unknown): v is string =>
  typeof v === 'string' && /^#[0-9a-fA-F]{3,8}$/.test(v)

Try / catch

try {
  await client.patch_app_config(patch)
} catch (e) {
  if (String(e).includes('Invalid theme color')) {
    showToast('Theme color must be in #RRGGBB format')
  }
}

Prevention

When it happens

Trigger: Patching verge config (validate_patch path) with theme_color set to a non-hex string like 'red', 'rgb(255,0,0)', or '#zzz'.

Common situations: Importing configs from older versions or third-party tools that stored named/rgb colors, or users typing arbitrary color strings in settings.

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


AI-assisted analysis of libnyanpasu/clash-nyanpasu@f7dbce2997 (2026-09-08). Data as JSON: /api/errors/3b9dfcf4342c8f6f. Report an issue: GitHub.