jlcodes99/cockpit-tools · error · std::io::Error

NotFound

NotFound

Error message

指定终端未找到

What it means

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.

Source

Thrown at src-tauri/src/commands/claude.rs:313

    #[cfg(target_os = "linux")]
    {
        let shell_command = format!("{}; exec bash", command);
        let mut cmd = if terminal == "system" || terminal.is_empty() {
            Command::new("x-terminal-emulator")
        } else {
            Command::new(&terminal)
        };

        cmd.args(["-e", "bash", "-lc", &shell_command])
            .spawn()
            .or_else(|_| {
                if terminal == "system" || terminal.is_empty() {
                    Command::new("gnome-terminal")
                        .args(["--", "bash", "-lc", &shell_command])
                        .spawn()
                } else {
                    Err(std::io::Error::new(
                        std::io::ErrorKind::NotFound,
                        "指定终端未找到",
                    ))
                }
            })
            .or_else(|_| {
                if terminal == "system" || terminal.is_empty() {
                    Command::new("konsole")
                        .args(["-e", "bash", "-lc", &shell_command])
                        .spawn()
                } else {
                    Err(std::io::Error::new(
                        std::io::ErrorKind::NotFound,
                        "指定终端未找到",
                    ))
                }
            })
            .or_else(|_| Command::new("sh").args(["-lc", command]).spawn())

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Set the terminal setting to "system" (or clear it) so the x-terminal-emulator/gnome-terminal/konsole fallback chain is used.
  2. Install the configured terminal emulator (e.g. `sudo apt install gnome-terminal`).
  3. Verify the terminal binary is on PATH (`which <terminal>`).
  4. 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.

Example fix

// before
Command::new(&terminal).args(["-e", "bash", "-lc", &shell_command]).spawn()
// after (verify first)
if which::which(&terminal).is_err() {
    log::warn!("terminal '{}' not found, falling back to system terminal", terminal);
    Command::new("x-terminal-emulator").args(["-e", "bash", "-lc", &shell_command]).spawn()
} else {
    Command::new(&terminal).args(["-e", "bash", "-lc", &shell_command]).spawn()
}
Defensive patterns

Strategy: validation

Validate before calling

// before launching, verify the terminal exists
fn terminal_available(t: &str) -> bool {
    t == "system" || t.is_empty() || which::which(t).is_ok()
}

Type guard

fn is_terminal_not_found(e: &std::io::Error) -> bool {
    e.kind() == std::io::ErrorKind::NotFound && e.to_string().contains("指定终端未找到")
}

Try / catch

match execute_claude_cli_command(&cmd) {
    Ok(msg) => Ok(msg),
    Err(e) if e.contains("指定终端未找到") => {
        // retry with system terminal
        execute_with_fallback("x-terminal-emulator", &cmd)
    }
    Err(e) => Err(e),
}

Prevention

When it happens

Trigger: 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`.

Common situations: 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.

Understand the failure class

Background: "Not Found" / HTTP 404 Errors: What They Mean and How to Fix Them Across Libraries — this error's family across 6 libraries.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/95388431b7103ce6. Report an issue: GitHub.