BigPizzaV3/CodexPlusPlus · error

invalid built-in Dream Skin theme draft

Error message

invalid built-in Dream Skin theme draft

What it means

prepare_dream_skin_activation special-cases built-in themes: a draft marked builtin must equal the default DreamSkinThemeConfig and carry an empty (whitespace-only) image_path. If either invariant is violated it bails with "invalid built-in Dream Skin theme draft", because a built-in theme by definition has no custom config or managed image.

Solutions

  1. Mark the draft builtin=false if it carries any custom config or image — only pristine defaults qualify as builtin
  2. Reset config to DreamSkinThemeConfig::default() and clear image_path when activating the built-in theme
  3. Build builtin drafts from a single canonical constructor so they cannot drift from the default
  4. Check for version drift: if DreamSkinThemeConfig::default() changed, rebuild the draft instead of reusing a cached one

Example fix

// before
let draft = DreamSkinThemeDraft { builtin: true, config: customized_config, image_path: "img.webp".into() };
// after
let draft = DreamSkinThemeDraft { builtin: true, config: DreamSkinThemeConfig::default(), image_path: String::new() };
Defensive patterns

Strategy: type-guard

Validate before calling

fn is_pristine_builtin(draft: &DreamSkinThemeDraft) -> bool {
    draft.builtin
        && draft.config == DreamSkinThemeConfig::default()
        && draft.image_path.trim().is_empty()
}

Type guard

fn require_builtin(draft: &DreamSkinThemeDraft) -> Result<&DreamSkinThemeDraft> {
    anyhow::ensure!(is_pristine_builtin(draft), "builtin drafts must equal default config with empty image_path");
    Ok(draft)
}

Try / catch

match prepare_dream_skin_activation(&state_dir, &draft) {
    Ok(activation) => apply(activation),
    Err(e) if e.to_string().contains("invalid built-in") => eprintln!("draft is marked builtin but carries custom config/image; unset builtin or reset the draft"),
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Calling prepare_dream_skin_activation with draft.builtin == true while draft.config differs from DreamSkinThemeConfig::default(), or draft.image_path is a non-empty (after trim) string — i.e. a mutated or fabricated builtin draft.

Common situations: Application code modified a builtin draft's config before activation (e.g. applying user customizations to a builtin theme); a deserialized draft incorrectly sets builtin=true on a custom theme; a refactoring changed DreamSkinThemeConfig::default() so a previously-matching draft no longer equals the default.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/981a5be358fad1a3. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/dream_skin_library.rs:419

}

pub fn rename_dream_skin_theme(
    state_dir: &Path,
    id: &str,
    name: &str,
) -> anyhow::Result<DreamSkinThemeSummary> {
    let mut draft = load_stored_dream_skin_theme(state_dir, id)?;
    draft.config.name = name.trim().to_string();
    save_dream_skin_theme(state_dir, &draft)
}

pub fn prepare_dream_skin_activation(
    state_dir: &Path,
    draft: &DreamSkinThemeDraft,
) -> anyhow::Result<DreamSkinActivation> {
    if draft.builtin {
        if draft.config != DreamSkinThemeConfig::default() || !draft.image_path.trim().is_empty() {
            bail!("invalid built-in Dream Skin theme draft");
        }
        crate::dream_skin::clear_managed_dream_skin_image(state_dir)?;
        return Ok(DreamSkinActivation {
            config: draft.config.clone(),
            active_image_path: String::new(),
        });
    }
    validate_theme_draft(draft)?;
    let managed_dir = state_dir.join("dream-skin/theme");
    let source = Path::new(draft.image_path.trim());
    let active_image = if let Some(extension) = stored_theme_image_extension(state_dir, source) {
        std::fs::create_dir_all(&managed_dir)
            .with_context(|| format!("failed to create {}", managed_dir.display()))?;
        let destination = managed_dir.join(format!("current.{extension}"));
        let bytes = std::fs::read(source)
            .with_context(|| format!("failed to read Dream Skin image {}", source.display()))?;
        crate::settings::atomic_write(&destination, &bytes).with_context(|| {
            format!("failed to store Dream Skin image {}", destination.display())

View on GitHub (pinned to b1ed92e5e4)