BigPizzaV3/CodexPlusPlus · error
only user scripts can be deleted
Error message
only user scripts can be deleted
What it means
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.
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.
Example fix
// before
manager.delete_user_script("my-script.js")?; // rejected
// after
let key = format!("user:{}", "my-script.js");
manager.delete_user_script(&key)?; Defensive patterns
Strategy: validation
Validate before calling
if !key.starts_with("user:") || key.len() <= "user:".len() {
eprintln!("{key} is not a user-owned script; delete not permitted");
return Ok(());
}
delete_user_script(&key)?; Type guard
fn user_script_key(key: &str) -> Option<&str> {
key.strip_prefix("user:").filter(|f| !f.is_empty() && !f.contains(['/', '\\']) && !matches!(*f, "." | ".."))
} Try / catch
match manager.delete_user_script(&key) {
Ok(removed) => refresh_inventory(),
Err(e) if e.to_string().contains("only user scripts can be deleted") => show_not_deletable_notice(&key),
Err(e) => return Err(e),
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- user-script runtime status must be a JSON object
- 主题包必须是 32 MiB 以内的普通 ZIP 文件
- 请填写 API 的模型名称
- 官方混合 API 不应在 auth.json 中保存 OPENAI_API_KEY。请清理此供应商的…
- 请填写 API 的模型名称
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/c13cc8873a8c8266.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/user_scripts.rs:150
pub fn set_global_enabled(&self, enabled: bool) -> anyhow::Result<UserScriptConfig> {
let _guard = self.config_lock.lock().unwrap();
let mut config = self.load_config_unlocked();
config.enabled = enabled;
self.save_config_unlocked(&config)?;
Ok(config)
}
pub fn set_script_enabled(&self, key: &str, enabled: bool) -> anyhow::Result<UserScriptConfig> {
let _guard = self.config_lock.lock().unwrap();
let mut config = self.load_config_unlocked();
config.scripts.insert(key.to_string(), enabled);
self.save_config_unlocked(&config)?;
Ok(config)
}
pub fn delete_user_script(&self, key: &str) -> anyhow::Result<UserScriptConfig> {
let Some(file_name) = key.strip_prefix("user:").filter(|value| !value.is_empty()) else {
anyhow::bail!("only user scripts can be deleted");
};
if file_name.contains(['/', '\\']) || file_name == "." || file_name == ".." {
anyhow::bail!("invalid user script key");
}
let path = self.user_dir.join(file_name);
let canonical_user_dir = self
.user_dir
.canonicalize()
.or_else(|_| {
fs::create_dir_all(&self.user_dir)?;
self.user_dir.canonicalize()
})
.with_context(|| {
format!(
"failed to resolve user script directory {}",
self.user_dir.display()
)
})?;View on GitHub (pinned to b1ed92e5e4)