{"record":{"id":"d990726001621a2d","repo":"BigPizzaV3/CodexPlusPlus","slug":"throw-new-error","errorCode":null,"errorMessage":"throw new Error({});","messagePattern":"throw new Error\\((.+?)\\);","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/user_scripts.rs","lineNumber":211,"sourceCode":"            \"enabled\": config.enabled,\n            \"builtin_dir\": self.builtin_dir.to_string_lossy(),\n            \"user_dir\": self.user_dir.to_string_lossy(),\n            \"scripts\": scripts\n        }))\n    }\n\n    pub fn build_enabled_bundle(&self) -> anyhow::Result<String> {\n        let config = self.load_config();\n        if !config.enabled {\n            return Ok(String::new());\n        }\n        let mut blocks = Vec::new();\n        for script in self.scan_script_files(&config)? {\n            if !script.enabled {\n                continue;\n            }\n            let source = fs::read_to_string(&script.path)\n                .unwrap_or_else(|error| format!(\"throw new Error({});\", json!(error.to_string())));\n            blocks.push(wrap_script(&script, &source));\n        }\n        Ok(blocks.join(\"\\n\"))\n    }\n\n    fn scan_scripts(\n        &self,\n        config: &UserScriptConfig,\n        runtime_status: Option<&Value>,\n    ) -> anyhow::Result<Vec<Value>> {\n        let runtime_scripts = runtime_status\n            .and_then(|value| value.get(\"scripts\").or(Some(value)))\n            .and_then(Value::as_object);\n        Ok(self\n            .scan_script_files(config)?\n            .into_iter()\n            .map(|script| {\n                let market = config.market.get(&script.key);","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/1f431ae49b57b3055e0e6845ba6156c6b4232b4d/crates/codex-plus-core/src/user_scripts.rs#L193-L229","documentation":"This is not a Rust error but JavaScript source text that build_enabled_bundle() embeds into the generated userscript bundle when fs::read_to_string() fails for an enabled script file (crates/codex-plus-core/src/user_scripts.rs:211). The Rust side deliberately succeeds (fault isolation): one unreadable script does not break bundle generation; instead the wrapped script throws at injection time in the page with the original io::Error message interpolated via json!(). The developer sees it in the browser/page console, not in the manager logs.","triggerScenarios":"Calling UserScripts::build_enabled_bundle() while an enabled script file (1) was deleted/renamed after scan_script_files() enumerated it, (2) is not readable due to OS permissions or an exclusive lock, or (3) contains non-UTF-8 bytes — read_to_string() fails on invalid UTF-8, and the error string is embedded into the JS throw.","commonSituations":"Script edited and saved in a non-UTF-8 encoding (e.g. GBK on Windows) by an external editor; file held with an exclusive lock by another process (editor/antivirus) on Windows; user manually removed a script directory while the manager was running; script synced by a cloud tool that replaced the file with a placeholder.","solutions":["Open the browser page console (or the CDP console) — the interpolated message inside throw new Error(...) names the exact io::Error and file, e.g. 'os error 13' (permission) or 'stream did not contain valid UTF-8'","Re-save the script file as UTF-8 (without BOM issues) and rebuild the bundle","Verify the file still exists at the path shown in the scan and is readable by the manager process","If the script is intentionally gone, disable it in the user-script config (enabled=false) or remove its entry so it is skipped instead of throwing"],"exampleFix":"# before: script saved as GBK, read_to_string fails, page throws\nfile: my-theme.user.js  (encoding: GBK)\n\n# after: convert to UTF-8 and rebuild the bundle\niconv -f GBK -t UTF-8 my-theme.user.js > my-theme.user.js.utf8 && mv my-theme.user.js.utf8 my-theme.user.js","handlingStrategy":"validation","validationCode":"// Rust, before calling build_enabled_bundle():\nfor script in scripts.scan_script_files(&config)? {\n    if !script.enabled { continue; }\n    let bytes = std::fs::read(&script.path)\n        .with_context(|| format!(\"script unreadable: {}\", script.path.display()))?;\n    std::str::from_utf8(&bytes)\n        .with_context(|| format!(\"script not UTF-8: {}\", script.path.display()))?;\n}","typeGuard":"fn script_is_loadable(path: &std::path::Path) -> bool {\n    std::fs::read(path)\n        .ok()\n        .and_then(|b| std::str::from_utf8(&b).ok().map(|_| true))\n        .unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Keep user scripts UTF-8 encoded; configure editors to enforce UTF-8","Validate readability + UTF-8 of every enabled script before rebuilding the bundle","Surface per-script read errors in the manager UI instead of shipping a throwing stub into the page","Disable scripts in config before deleting their files"],"tags":["userscripts","javascript-injection","filesystem","encoding","utf-8"],"backgroundTag":"file-read-failed","analyzedSha":"1f431ae49b57b3055e0e6845ba6156c6b4232b4d","analyzedAt":"2026-08-16T20:54:18.598Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}