atuinsh/atuin · error
Failed to get current PID
Error message
Failed to get current PID
What it means
Shell::current identifies the shell that spawned atuin by walking the process tree via the sysinfo crate. It first calls get_current_pid() and unwraps it with expect; if the sysinfo/OS call cannot determine the current PID, the process panics with 'Failed to get current PID'.
Solutions
- Run on a supported OS (Linux, macOS, Windows, BSDs) where process IDs are retrievable.
- Check sysinfo version compatibility if built for an unusual target; upgrade/downgrade the crate.
- Replace the expect with graceful error handling if you embed atuin-common in an environment without PID support.
- Report the platform/target to atuin maintainers if a supported OS still hits this.
Example fix
// before
let process = sys.process(get_current_pid().expect("Failed to get current PID"))
.expect("Process with current pid does not exist");
// after
let pid = match get_current_pid() {
Ok(pid) => pid,
Err(e) => return Err(format!("cannot determine current pid: {e}")),
}; Defensive patterns
Strategy: try-catch
Validate before calling
// Rust: detect PID availability before calling Shell::current (best-effort)
fn pid_available() -> bool {
std::process::id() != 0 && std::env::var_os("SHELL").is_some()
} Try / catch
// Rust: expect() panics — contain it or avoid it
let shell = std::panic::catch_unwind(Shell::current)
.unwrap_or_else(|_| Shell::from_string(&std::env::var("SHELL").unwrap_or_default())); Prevention
- Run on platforms where sysinfo can resolve PIDs (Linux/macOS/Windows/BSD).
- Prefer Shell::from_string with an explicit shell name in embedded or sandboxed contexts.
- Keep the sysinfo crate version compatible with your target.
- Report unsupported targets upstream instead of patching around them silently.
When it happens
Trigger: Calling Shell::current (used during history capture / shell detection) on a platform where the `sysinfo` get_current_pid() helper fails — effectively never on Linux/macOS/Windows, but possible on unsupported or heavily sandboxed targets.
Common situations: Running atuin on an exotic or restricted platform where /proc or the OS process APIs are unavailable; linking a sysinfo version whose platform backend fails for the current target.
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
- Atuin running with no parent!
- Process with current pid does not exist
- Process with parent pid does not exist
- clone pty reader
- Could not build config
AI-assisted analysis of atuinsh/atuin@c0c717ab04 (2026-09-12).
Data as JSON: /api/errors/91886c19964bd619.
Report an issue: GitHub.
Appendix: source
Thrown at crates/atuin-common/src/shell.rs:44
Unknown,
}
#[derive(Debug, Error, Serialize)]
pub enum ShellError {
#[error("shell not supported")]
NotSupported,
#[error("failed to execute shell command: {0}")]
ExecError(String),
}
impl Shell {
#[must_use]
pub fn current() -> Self {
let sys = System::new_all();
let process = sys
.process(get_current_pid().expect("Failed to get current PID"))
.expect("Process with current pid does not exist");
let parent = sys
.process(process.parent().expect("Atuin running with no parent!"))
.expect("Process with parent pid does not exist");
let shell = parent.name().to_string_lossy().trim().to_lowercase();
let shell = shell.strip_prefix('-').unwrap_or(&shell);
Self::from_string(shell)
}
#[must_use]
pub fn from_env() -> Self {
std::env::var("ATUIN_SHELL")
.map_or(Self::Unknown, |shell| Self::from_string(&shell.trim().to_lowercase()))
}
View on GitHub (pinned to c0c717ab04)