{"record":{"id":"91886c19964bd619","repo":"atuinsh/atuin","slug":"failed-to-get-current-pid","errorCode":null,"errorMessage":"Failed to get current PID","messagePattern":"Failed to get current PID","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/atuin-common/src/shell.rs","lineNumber":41,"sourceCode":"    #[display(\"unknown\")]\n    Unknown,\n}\n\n#[derive(Debug, Error, Serialize)]\npub enum ShellError {\n    #[error(\"shell not supported\")]\n    NotSupported,\n\n    #[error(\"failed to execute shell command: {0}\")]\n    ExecError(String),\n}\n\nimpl Shell {\n    pub fn current() -> Shell {\n        let sys = System::new_all();\n\n        let process = sys\n            .process(get_current_pid().expect(\"Failed to get current PID\"))\n            .expect(\"Process with current pid does not exist\");\n\n        let parent = sys\n            .process(process.parent().expect(\"Atuin running with no parent!\"))\n            .expect(\"Process with parent pid does not exist\");\n\n        let shell = parent.name().trim().to_lowercase();\n        let shell = shell.strip_prefix('-').unwrap_or(&shell);\n\n        Shell::from_string(shell.to_string())\n    }\n\n    pub fn from_env() -> Shell {\n        std::env::var(\"ATUIN_SHELL\").map_or(Shell::Unknown, |shell| {\n            Shell::from_string(shell.trim().to_lowercase())\n        })\n    }\n","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/atuinsh/atuin/blob/202f6ad98ee0da165c35cdb2afbc5b13d6ab81a1/crates/atuin-common/src/shell.rs#L23-L59","documentation":"A panic in Shell::current (atuin-common) when sysinfo's get_current_pid() returns an error, i.e. the platform cannot report Atuin's own process ID. Shell::current walks sysinfo's process table to find its parent process (the shell that invoked Atuin) and derive the shell from its name; the very first step, obtaining its own PID, is unwrapped with expect. It is a platform-support failure in sysinfo, not something config or usage causes — and note the sibling expects after it ('Atuin running with no parent!', process lookup) can equally abort exotic setups.","triggerScenarios":"Running Shell::current() on a platform/target where sysinfo cannot enumerate processes or provide the current PID (some containers, sandboxes, wasm, or Tier-3 OS targets); typically during shell-hook init or commands that need to detect the invoking shell.","commonSituations":"Running Atuin inside minimal sandboxes or exotic emulated environments where /proc is absent or process introspection is blocked; cross-compiled builds on unsupported operating systems.","solutions":["Set the ATUIN_SHELL environment variable to your shell name and prefer Shell::from_env(), which reads it without any process-table walk","Run on a platform sysinfo supports (any mainstream Linux/macOS/Windows/BSD)","Fix the sandbox/container so /proc is mounted and readable","In embedding code, call Shell::from_env() or Shell::from_string() instead of Shell::current() to avoid the panic path entirely"],"exampleFix":"// before\nlet shell = Shell::current(); // panics if sysinfo cannot get our PID\n// after\nlet shell = std::env::var(\"ATUIN_SHELL\")\n    .map(|s| Shell::from_string(s.trim().to_lowercase()))\n    .unwrap_or_else(|_| Shell::current());","handlingStrategy":"fallback","validationCode":"// Prefer environment-based detection; only fall back to process introspection\nstd::env::set_var(\"ATUIN_SHELL\", \"zsh\"); // set in shell init files before invoking atuin\nlet shell = Shell::from_env(); // never panics: Unknown when var absent","typeGuard":"fn shell_detectable() -> bool {\n    // sysinfo needs a readable /proc (linux) or supported process API\n    cfg!(any(target_os = \"linux\", target_os = \"macos\", target_os = \"windows\", target_os = \"freebsd\"))\n        && std::path::Path::new(\"/proc\").exists() || cfg!(not(target_os = \"linux\"))\n}","tryCatchPattern":"// expect() panic: not catchable as an error. Avoid the panic path by preferring\n// Shell::from_env() (reads ATUIN_SHELL, returns Shell::Unknown instead of panicking)\n// or Shell::from_string(name) when the caller already knows the shell.","preventionTips":["Export ATUIN_SHELL in your shell's init file so Atuin never needs process introspection","Use Shell::from_env()/from_string() instead of Shell::current() in embedding code","Ensure /proc is mounted and readable in containers/sandboxes running Atuin","Verify sysinfo supports your platform before porting"],"tags":["shell","platform","panic","sysinfo","process","rust","atuin"],"backgroundTag":"process-introspection-unsupported","analyzedSha":"202f6ad98ee0da165c35cdb2afbc5b13d6ab81a1","analyzedAt":"2026-08-16T19:30:24.731Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}