ClementTsang/bottom · error

Error code unknown

Error message

Error code unknown - {err}

What it means

Sibling of the `Error code {err_code}` bail in the Unix `kill_process_given_pid`: when `std::io::Error::last_os_error().raw_os_error()` returns `None` — i.e. the OS did not report a recognizable errno — the library bails with `Error code unknown - {err}` (err will read 'Unknown error occurred.'). This is a rare fallback path meaning `libc::kill` failed but the thread-local errno could not be interpreted.

Solutions

  1. Retry the kill once and inspect the new error — transient errno clobbering is usually not reproducible
  2. Check that the PID is valid and the signal value is in range, then retry with a corrected call
  3. Capture `std::io::Error::last_os_error()` display text for the real cause and report it upstream if it persists
Defensive patterns

Strategy: retry

Try / catch

match kill_process_given_pid(pid, signal) {
    Err(e) if e.to_string().contains("Error code unknown") => {
        // retry once; errno was unreadable
        if let Err(e2) = kill_process_given_pid(pid, signal) {
            eprintln!("kill retry failed: {e2}");
        }
    }
    other => { let _ = other; }
}

Prevention

When it happens

Trigger: `libc::kill` returned non-zero but `last_os_error()` produced an error without a raw errno (e.g. errno was clobbered by an intervening call, or the error carried no OS code).

Common situations: Unusual libc/platform conditions or interleaving code between the failed `kill` and the errno read on exotic libc implementations; very rare in practice on standard Linux/macOS.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of ClementTsang/bottom@b77d317502 (2026-09-07). Data as JSON: /api/errors/b899dccca3cb645f. Report an issue: GitHub.

Appendix: source

Thrown at src/utils/process_killer.rs:83

    // code not 0).
    let output = unsafe { libc::kill(pid, signal as i32) };

    if output != 0 {
        // We had an error...
        let err_code = std::io::Error::last_os_error().raw_os_error();
        let err = match err_code {
            Some(libc::ESRCH) => "the target process did not exist.",
            Some(libc::EPERM) => {
                "the calling process does not have the permissions to terminate the target process(es)."
            }
            Some(libc::EINVAL) => "an invalid signal was specified.",
            _ => "Unknown error occurred.",
        };

        if let Some(err_code) = err_code {
            bail!(format!("Error code {err_code} - {err}"))
        } else {
            bail!(format!("Error code unknown - {err}"))
        };
    }

    Ok(())
}

View on GitHub (pinned to b77d317502)