{"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":44,"sourceCode":"    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    #[must_use]\n    pub fn current() -> Self {\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().to_string_lossy().trim().to_lowercase();\n        let shell = shell.strip_prefix('-').unwrap_or(&shell);\n\n        Self::from_string(shell)\n    }\n\n    #[must_use]\n    pub fn from_env() -> Self {\n        std::env::var(\"ATUIN_SHELL\")\n            .map_or(Self::Unknown, |shell| Self::from_string(&shell.trim().to_lowercase()))\n    }\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/atuinsh/atuin/blob/c0c717ab04c881764bcad4b3d169a507e2432643/crates/atuin-common/src/shell.rs#L26-L62","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nlet process = sys.process(get_current_pid().expect(\"Failed to get current PID\"))\n    .expect(\"Process with current pid does not exist\");\n\n// after\nlet pid = match get_current_pid() {\n    Ok(pid) => pid,\n    Err(e) => return Err(format!(\"cannot determine current pid: {e}\")),\n};","handlingStrategy":"try-catch","validationCode":"// Rust: detect PID availability before calling Shell::current (best-effort)\nfn pid_available() -> bool {\n    std::process::id() != 0 && std::env::var_os(\"SHELL\").is_some()\n}","typeGuard":null,"tryCatchPattern":"// Rust: expect() panics — contain it or avoid it\nlet shell = std::panic::catch_unwind(Shell::current)\n    .unwrap_or_else(|_| Shell::from_string(&std::env::var(\"SHELL\").unwrap_or_default()));","preventionTips":["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."],"tags":["process","panic","sysinfo","shell-detection"],"backgroundTag":"internal-invariant-violation","analyzedSha":"c0c717ab04c881764bcad4b3d169a507e2432643","analyzedAt":"2026-09-12T07:40:01.341Z","contentChangedAt":"2026-09-12T07:40:01.341Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}