{"record":{"id":"c13cc8873a8c8266","repo":"BigPizzaV3/CodexPlusPlus","slug":"only-user-scripts-can-be-deleted","errorCode":null,"errorMessage":"only user scripts can be deleted","messagePattern":"only user scripts can be deleted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/user_scripts.rs","lineNumber":150,"sourceCode":"    pub fn set_global_enabled(&self, enabled: bool) -> anyhow::Result<UserScriptConfig> {\n        let _guard = self.config_lock.lock().unwrap();\n        let mut config = self.load_config_unlocked();\n        config.enabled = enabled;\n        self.save_config_unlocked(&config)?;\n        Ok(config)\n    }\n\n    pub fn set_script_enabled(&self, key: &str, enabled: bool) -> anyhow::Result<UserScriptConfig> {\n        let _guard = self.config_lock.lock().unwrap();\n        let mut config = self.load_config_unlocked();\n        config.scripts.insert(key.to_string(), enabled);\n        self.save_config_unlocked(&config)?;\n        Ok(config)\n    }\n\n    pub fn delete_user_script(&self, key: &str) -> anyhow::Result<UserScriptConfig> {\n        let Some(file_name) = key.strip_prefix(\"user:\").filter(|value| !value.is_empty()) else {\n            anyhow::bail!(\"only user scripts can be deleted\");\n        };\n        if file_name.contains(['/', '\\\\']) || file_name == \".\" || file_name == \"..\" {\n            anyhow::bail!(\"invalid user script key\");\n        }\n        let path = self.user_dir.join(file_name);\n        let canonical_user_dir = self\n            .user_dir\n            .canonicalize()\n            .or_else(|_| {\n                fs::create_dir_all(&self.user_dir)?;\n                self.user_dir.canonicalize()\n            })\n            .with_context(|| {\n                format!(\n                    \"failed to resolve user script directory {}\",\n                    self.user_dir.display()\n                )\n            })?;","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/user_scripts.rs#L132-L168","documentation":"delete_user_script only permits deleting scripts owned by the user, identified by a `user:` key prefix (e.g. `user:my-script.js`). Market/builtin scripts are managed elsewhere and must not be removed through this API, so any key without the `user:` prefix — or with an empty remainder — is rejected.","triggerScenarios":"Calling delete_user_script(key) with a market-script key (no `user:` prefix), a builtin script key, a bare filename like `my-script.js`, or an empty string / literal `user:` with nothing after it.","commonSituations":"UI wiring passing the wrong key field (script name instead of its inventory key); iterating the combined inventory (user + market scripts) and deleting everything; tests like user_script_manager_deletes_market_script_metadata_and_rejects_builtin_delete exercising this rejection.","solutions":["Pass the full inventory key including the `user:` prefix, e.g. `delete_user_script(\"user:my-script.js\")`.","Only surface the delete action for entries whose key starts with `user:` in the UI.","To remove market scripts, use the market-management API (uninstall/remove) instead of delete_user_script."],"exampleFix":"// before\nmanager.delete_user_script(\"my-script.js\")?; // rejected\n// after\nlet key = format!(\"user:{}\", \"my-script.js\");\nmanager.delete_user_script(&key)?;","handlingStrategy":"validation","validationCode":"if !key.starts_with(\"user:\") || key.len() <= \"user:\".len() {\n    eprintln!(\"{key} is not a user-owned script; delete not permitted\");\n    return Ok(());\n}\ndelete_user_script(&key)?;","typeGuard":"fn user_script_key(key: &str) -> Option<&str> {\n    key.strip_prefix(\"user:\").filter(|f| !f.is_empty() && !f.contains(['/', '\\\\']) && !matches!(*f, \".\" | \"..\"))\n}","tryCatchPattern":"match manager.delete_user_script(&key) {\n    Ok(removed) => refresh_inventory(),\n    Err(e) if e.to_string().contains(\"only user scripts can be deleted\") => show_not_deletable_notice(&key),\n    Err(e) => return Err(e),\n}","preventionTips":["Always carry the full `user:`-prefixed inventory key, not the bare script name, into delete calls.","In the UI, enable delete only for entries whose key starts with `user:`.","Route market-script removal through its dedicated uninstall API."],"tags":["user-scripts","validation","delete","key-format"],"backgroundTag":"invalid-identifier-format","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"}