{"record":{"id":"95388431b7103ce6","repo":"jlcodes99/cockpit-tools","slug":"notfound","errorCode":"NotFound","errorMessage":"指定终端未找到","messagePattern":"指定终端未找到","errorType":"error_code","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/src/commands/claude.rs","lineNumber":313,"sourceCode":"\n    #[cfg(target_os = \"linux\")]\n    {\n        let shell_command = format!(\"{}; exec bash\", command);\n        let mut cmd = if terminal == \"system\" || terminal.is_empty() {\n            Command::new(\"x-terminal-emulator\")\n        } else {\n            Command::new(&terminal)\n        };\n\n        cmd.args([\"-e\", \"bash\", \"-lc\", &shell_command])\n            .spawn()\n            .or_else(|_| {\n                if terminal == \"system\" || terminal.is_empty() {\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 terminal == \"system\" || terminal.is_empty() {\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":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src-tauri/src/commands/claude.rs#L295-L331","documentation":"On Linux, `execute_claude_cli_command` tries a chain of terminal emulators (x-terminal-emulator, then gnome-terminal, konsole, finally sh). This error (ErrorKind::NotFound, \"指定终端未找到\") is returned from the gnome-terminal fallback branch when the user requested a specific non-system terminal (`terminal` not \"system\"/empty) — meaning `Command::new(&terminal).spawn()` already failed because that terminal binary is not installed, and the branch deliberately yields NotFound instead of trying gnome-terminal.","triggerScenarios":"User configured a named terminal (e.g. \"alacritty\", \"kitty\") that is not installed, so the primary spawn fails; because `terminal != \"system\"`, the gnome-terminal fallback arm evaluates to `Err(NotFound)` before the chain continues to konsole and finally plain `sh`.","commonSituations":"Settings point to a terminal that was uninstalled; running on a minimal Linux distro without the configured emulator; typo in the terminal name in app settings.","solutions":["Set the terminal setting to \"system\" (or clear it) so the x-terminal-emulator/gnome-terminal/konsole fallback chain is used.","Install the configured terminal emulator (e.g. `sudo apt install gnome-terminal`).","Verify the terminal binary is on PATH (`which <terminal>`).","The chain still falls through to `sh -lc`, so check whether the reported failure was surfaced from the final map_err rather than this branch."],"exampleFix":"// before\nCommand::new(&terminal).args([\"-e\", \"bash\", \"-lc\", &shell_command]).spawn()\n// after (verify first)\nif which::which(&terminal).is_err() {\n    log::warn!(\"terminal '{}' not found, falling back to system terminal\", terminal);\n    Command::new(\"x-terminal-emulator\").args([\"-e\", \"bash\", \"-lc\", &shell_command]).spawn()\n} else {\n    Command::new(&terminal).args([\"-e\", \"bash\", \"-lc\", &shell_command]).spawn()\n}","handlingStrategy":"validation","validationCode":"// before launching, verify the terminal exists\nfn terminal_available(t: &str) -> bool {\n    t == \"system\" || t.is_empty() || which::which(t).is_ok()\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 execute_claude_cli_command(&cmd) {\n    Ok(msg) => Ok(msg),\n    Err(e) if e.contains(\"指定终端未找到\") => {\n        // retry with system terminal\n        execute_with_fallback(\"x-terminal-emulator\", &cmd)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Validate the terminal setting against installed binaries when it is saved.","Offer a 'detect terminals' picker that only lists `which`-verifiable emulators.","Default to \"system\" on fresh installs."],"tags":["rust","linux","terminal","not-found","spawn"],"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"}