{"record":{"id":"236c8db6b7d41301","repo":"atuinsh/atuin","slug":"failed-to-execute-script","errorCode":null,"errorMessage":"failed to execute script","messagePattern":"failed to execute script","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/atuin/src/command/client/scripts.rs","lineNumber":158,"sourceCode":"        let (command, args) = parts.split_first().ok_or_eyre(\"No editor command found\")?;\n\n        let status = std::process::Command::new(command).args(args).arg(&path).status()?;\n        if !status.success() {\n            bail!(\"failed to open editor\");\n        }\n\n        // Read back the edited content\n        let content = std::fs::read_to_string(&path)?;\n        path.close()?;\n\n        Ok(content)\n    }\n\n    // Helper function to execute a script and manage stdin/stdout/stderr\n    async fn execute_script(script_content: String, shebang: String) -> Result<i32> {\n        let mut session = execute_script_interactive(script_content, shebang)\n            .await\n            .expect(\"failed to execute script\");\n\n        // Create a channel to signal when the process exits\n        let (exit_tx, mut exit_rx) = tokio::sync::oneshot::channel();\n\n        // Set up a task to read from stdin and forward to the script\n        let sender = session.stdin_tx.clone();\n        let stdin_task = tokio::spawn(async move {\n            use tokio::io::AsyncReadExt;\n            use tokio::select;\n\n            let stdin = tokio::io::stdin();\n            let mut reader = tokio::io::BufReader::new(stdin);\n            let mut buffer = vec![0u8; 1024]; // Read in chunks for efficiency\n\n            loop {\n                // Use select to either read from stdin or detect when the process exits\n                select! {\n                    // Check if the script process has exited","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/atuinsh/atuin/blob/900007c48045867e7f44b0f9bc55ad9dbe99ee0d/crates/atuin/src/command/client/scripts.rs#L140-L176","documentation":"`execute_script` in the scripts command launches a script via `execute_script_interactive` and `.expect(\"failed to execute script\")`s if the child process (shebang interpreter) cannot be spawned or its pty session cannot be set up. This is a panic, not a handled error, meaning the interpreter binary referenced by the shebang is missing/unavailable or the pty allocation failed.","triggerScenarios":"Running a stored atuin script whose shebang names an interpreter not present on PATH (e.g. `#!/usr/bin/env zsh` with zsh absent), or when `execute_script_interactive` fails to allocate the pty/spawn the process at crates/atuin/src/command/client/scripts.rs:158.","commonSituations":"Syncing scripts between machines where the shebang interpreter exists on one host but not another; running scripts in minimal containers lacking bash/zsh/python; bad shebang lines saved into the script store.","solutions":["Install the interpreter named in the script's shebang (e.g. `apt install zsh`).","Fix the script's shebang line to point to an available interpreter (`#!/usr/bin/env bash`).","Verify the interpreter path exists: `which <interpreter>` or `command -v <interpreter>` before running."],"exampleFix":"// before (stored script content)\n#!/usr/bin/env zsh\necho hello\n// after\n#!/usr/bin/env bash\necho hello","handlingStrategy":"validation","validationCode":"# verify the shebang interpreter exists before executing a stored script\ninterp=$(head -n1 script.sh | sed 's|^#!||; s|.*env ||')\ncommand -v \"$interp\" >/dev/null || { echo \"interpreter '$interp' not installed\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer `#!/usr/bin/env <interpreter>` with widely installed interpreters (bash, sh).","Audit stored scripts' shebangs after syncing to a new machine or container.","Pin required interpreters in container images that run atuin scripts."],"tags":["script-execution","interpreter-not-found","shebang","panic"],"backgroundTag":"command-not-found","analyzedSha":"900007c48045867e7f44b0f9bc55ad9dbe99ee0d","analyzedAt":"2026-09-19T12:52:51.491Z","contentChangedAt":"2026-09-19T12:52:51.491Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}