{"record":{"id":"56a41bd6dca031dd","repo":"BigPizzaV3/CodexPlusPlus","slug":"current-dream-skin-theme-cannot-be-deleted","errorCode":null,"errorMessage":"current Dream Skin theme cannot be deleted","messagePattern":"current Dream Skin theme cannot be deleted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_library.rs","lineNumber":495,"sourceCode":"                .with_context(|| format!(\"failed to remove old image {}\", path.display()))?;\n        }\n    }\n    Ok(DreamSkinActivation {\n        config: draft.config.clone(),\n        active_image_path: active_image.to_string_lossy().into_owned(),\n    })\n}\n\npub fn delete_dream_skin_theme(\n    state_dir: &Path,\n    id: &str,\n    active_id: Option<&str>,\n) -> anyhow::Result<()> {\n    if !valid_theme_id(id) {\n        bail!(\"invalid Dream Skin theme id\");\n    }\n    if active_id.is_some_and(|active| active == id) {\n        bail!(\"current Dream Skin theme cannot be deleted\");\n    }\n    let directory = state_dir.join(THEMES_DIR).join(id);\n    let metadata = std::fs::symlink_metadata(&directory)\n        .with_context(|| format!(\"Dream Skin theme not found: {id}\"))?;\n    if !metadata.file_type().is_dir() || metadata.file_type().is_symlink() {\n        bail!(\"Dream Skin theme path is not a safe directory\");\n    }\n    let stored = load_stored_dream_skin_theme(state_dir, id)?;\n    if stored.config.id == DreamSkinThemeConfig::default().id {\n        bail!(\"built-in Dream Skin theme cannot be deleted\");\n    }\n    remove_known_theme_directory(&directory)\n}\n\nfn validate_theme_draft(draft: &DreamSkinThemeDraft) -> anyhow::Result<()> {\n    if draft.builtin {\n        bail!(\"built-in Dream Skin theme is read-only\");\n    }","sourceCodeStart":477,"sourceCodeEnd":513,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_library.rs#L477-L513","documentation":"delete_dream_skin_theme refuses to delete the theme whose id equals the active_id parameter, since deleting the currently active Dream Skin theme would leave the UI referencing a missing theme. The check runs after id validation and before any filesystem access. Passing the active theme's id here is an API-contract violation, not a filesystem problem.","triggerScenarios":"Calling delete_dream_skin_theme(state_dir, id, Some(id)) — i.e. Some(&active_theme_id) where the id being deleted equals the currently active theme's id.","commonSituations":"UI delete button enabled while the theme is active; batch-delete loops that don't skip the active theme; stale active_id state in config so the caller believes another theme is active; calling with active_id that was updated after theme switch but before delete.","solutions":["Switch the active theme to another valid theme (update stored active_id) before calling delete on the current one.","Check active_id before calling and skip or surface a user-facing 'cannot delete active theme' message.","If the caller doesn't know the active theme, load it from config/state first and pass it correctly — do NOT pass None as a workaround when the theme actually is active."],"exampleFix":"// before\ndelete_dream_skin_theme(&state_dir, &theme_id, Some(&active_id))?; // panics when equal\n// after\nif theme_id == active_id {\n    let fallback = themes.iter().find(|t| t.config.id != active_id)\n        .ok_or_else(|| anyhow!(\"no other theme to activate\"))?;\n    set_active_dream_skin_theme(&state_dir, &fallback.config.id)?;\n}\ndelete_dream_skin_theme(&state_dir, &theme_id, Some(&active_id))?;","handlingStrategy":"validation","validationCode":"if let Some(active) = active_id {\n    if active == id { return Err(anyhow!(\"switch away from the active theme before deleting it\")); }\n}","typeGuard":null,"tryCatchPattern":"match delete_dream_skin_theme(&state_dir, &id, active_id) {\n    Err(e) if e.to_string().contains(\"cannot be deleted\") => ui_show(\"Cannot delete the active theme; switch first\"),\n    other => other?,\n}","preventionTips":["Disable the delete action in the UI while a theme is active.","In batch deletes, always skip or re-activate away from the current theme first.","Keep active_id in sync — load it from state immediately before deleting."],"tags":["validation","state-conflict","theme","rust"],"backgroundTag":"invalid-state-transition","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}