{"record":{"id":"5709832f960ae2f0","repo":"jlcodes99/cockpit-tools","slug":"notfound-570983","errorCode":"NotFound","errorMessage":"指定终端未找到","messagePattern":"指定终端未找到","errorType":"error_code","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/src/commands/codex_instance.rs","lineNumber":4037,"sourceCode":"            .map_err(|e| format!(\"打开终端失败 ({}): {}\", plan.terminal_name, e))?;\n        drop(child);\n        return Ok(format!(\"已在 {} 执行 Codex CLI 命令\", plan.terminal_name));\n    }\n\n    #[cfg(target_os = \"linux\")]\n    {\n        let shell_command = format!(\"{}; exec bash\", command);\n        let use_system_terminal = terminal.is_empty() || terminal.eq_ignore_ascii_case(\"system\");\n        let launch_result = Command::new(&plan.program)\n            .args(&plan.args)\n            .spawn()\n            .or_else(|_| {\n                if use_system_terminal {\n                    Command::new(\"gnome-terminal\")\n                        .args([\"--\", \"bash\", \"-lc\", &shell_command])\n                        .spawn()\n                } else {\n                    Err(std::io::Error::new(\n                        std::io::ErrorKind::NotFound,\n                        \"指定终端未找到\",\n                    ))\n                }\n            })\n            .or_else(|_| {\n                if use_system_terminal {\n                    Command::new(\"konsole\")\n                        .args([\"-e\", \"bash\", \"-lc\", &shell_command])\n                        .spawn()\n                } else {\n                    Err(std::io::Error::new(\n                        std::io::ErrorKind::NotFound,\n                        \"指定终端未找到\",\n                    ))\n                }\n            })\n            .or_else(|_| Command::new(\"sh\").args([\"-lc\", &command]).spawn());","sourceCodeStart":4019,"sourceCodeEnd":4055,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src-tauri/src/commands/codex_instance.rs#L4019-L4055","documentation":"In `src-tauri/src/commands/codex_instance.rs` (around line 4037), the Linux terminal spawn chain for launching a Codex instance hits the gnome-terminal fallback branch; when the request is for a specific terminal (`use_system_terminal == false`) and the earlier spawn failed, the branch returns `Err(ErrorKind::NotFound, \"指定终端未找到\")`. It indicates the explicitly selected terminal emulator could not be spawned.","triggerScenarios":"Launching a Codex instance CLI with a named terminal on Linux where `Command::new(<terminal>)` fails (binary not installed / not on PATH) and `use_system_terminal` is false, so the gnome-terminal arm short-circuits with NotFound.","commonSituations":"User picked a terminal in Codex instance settings that is not installed; headless/minimal Linux environments missing GUI terminals; PATH differs between the app's launch context and the user's shell.","solutions":["Enable \"use system terminal\" for the instance so the x-terminal-emulator/gnome-terminal/konsole fallbacks apply.","Install the selected terminal emulator or fix its PATH entry.","Update the instance's terminal setting to an installed emulator.","The chain still falls through to further fallbacks and finally `sh -lc`; verify which link actually surfaced the error in the returned message."],"exampleFix":"// before\nErr(std::io::Error::new(std::io::ErrorKind::NotFound, \"指定终端未找到\"))\n// after\nErr(std::io::Error::new(\n    std::io::ErrorKind::NotFound,\n    format!(\"无法启动指定终端（未安装或不在 PATH 中）。请在设置中改用系统终端。\"),\n))","handlingStrategy":"validation","validationCode":"// before spawn: check the requested binary\nif !use_system_terminal && which::which(&terminal).is_err() {\n    return Err(format!(\"指定终端未安装: {}\", terminal));\n}","typeGuard":"fn is_terminal_not_found(e: &std::io::Error) -> bool {\n    e.kind() == std::io::ErrorKind::NotFound && e.to_string().contains(\"指定终端未找到\")\n}","tryCatchPattern":"match launch_codex_instance(&cfg) {\n    Ok(pid) => Ok(pid),\n    Err(e) if e.contains(\"指定终端未找到\") => {\n        launch_codex_instance(&cfg.with_system_terminal())\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Verify the terminal binary exists when persisting instance settings.","Prefer the system-terminal option in headless or minimal environments.","Include the terminal name in error messages for faster diagnosis."],"tags":["rust","linux","terminal","codex","not-found"],"backgroundTag":"terminal-not-found","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}