{"record":{"id":"a595903a8a319817","repo":"jdx/mise","slug":"exec-command-failed","errorCode":null,"errorMessage":"exec command failed: {}","messagePattern":"exec command failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/tera.rs","lineNumber":1466,"sourceCode":"            .collect::<Vec<String>>();\n        let mut env_no_shims = env.clone();\n        if let Some(path_val) = env_no_shims.get(&*env::PATH_KEY).cloned() {\n            env_no_shims.insert(env::PATH_KEY.to_string(), strip_shims_from_path(&path_val));\n        }\n        let run_once = || -> eyre::Result<String> {\n            #[cfg(windows)]\n            {\n                if let Some(mut c) =\n                    crate::path::cmd_verbatim_command(&shell[0], &shell[1..], command)\n                {\n                    c.env_clear();\n                    c.envs(env_no_shims.iter());\n                    if let Some(dir) = &dir {\n                        c.current_dir(dir);\n                    }\n                    let out = c.output()?;\n                    if !out.status.success() {\n                        eyre::bail!(\n                            \"exec command failed: {}\",\n                            String::from_utf8_lossy(&out.stderr)\n                        );\n                    }\n                    let mut s = String::from_utf8(out.stdout)?;\n                    while s.ends_with('\\n') || s.ends_with('\\r') {\n                        s.pop();\n                    }\n                    return Ok(s);\n                }\n            }\n            let mut expr: duct::Expression = cmd(&shell[0], &shell_args).full_env(&env_no_shims);\n            if let Some(dir) = &dir {\n                expr = expr.dir(dir);\n            }\n            Ok(crate::inline_command::optimize_expression(\n                expr,\n                command,","sourceCodeStart":1448,"sourceCodeEnd":1484,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/tera.rs#L1448-L1484","documentation":"The Tera v1 template `exec` function runs a shell command as a subprocess and requires it to exit successfully; on a non-zero status mise bails with the command's stderr as the message. Template rendering thus fails whenever an embedded exec command fails.","triggerScenarios":"A mise.toml template uses `{{ exec(command=\"...\") }}` (or parse_template/get_tera_v1 evaluates a template containing it) and the command exits non-zero — e.g. missing binary, failing script, or wrong cwd/dir argument.","commonSituations":"Referencing a command not installed in the environment the task runs in; a script that depends on files in the wrong working directory; environment differences (env_no_shims) hiding tools normally available via shims.","solutions":["Run the failing command manually and fix why it exits non-zero (the stderr in the error shows the cause)","Ensure the command is installed/on PATH for the mise environment (shims are stripped from exec env)","Check the `dir` argument of the exec call points to the intended working directory"],"exampleFix":"// before (template)\n{{ exec(command=\"git rev-parse --verify HEAD^9\") }}\n\n// after\n{{ exec(command=\"git rev-parse --verify HEAD~9 || echo unknown\") }}","handlingStrategy":"try-catch","validationCode":"// pre-check a command before embedding it in a template\nconst { status } = Bun.spawnSync(['git', 'rev-parse', 'HEAD']);\nif (status !== 0) throw new Error('git not usable in mise exec environment');","typeGuard":null,"tryCatchPattern":"// wrap template rendering that uses exec()\nmatch render() {\n    Err(e) if e.to_string().contains(\"exec command failed\") => {\n        eprintln!(\"template exec failed: {e:#}; check PATH/dir of embedded command\");\n    }\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Remember exec strips mise shims from the environment — only real PATH tools run","Test template commands in a bare shell first","Give exec an explicit dir argument when the command depends on cwd","Make embedded commands defensive (|| echo fallback) when failure is tolerable"],"tags":["tera","template","subprocess","command"],"backgroundTag":"command-not-found","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}