{"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":1525,"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":1507,"sourceCodeEnd":1543,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/tera.rs#L1507-L1543","documentation":"The Tera v1 `exec` template function runs a shell command during template rendering and requires a zero exit status. On non-zero exit, mise bails with the command's stderr as the message, so template rendering aborts. This surfaces underlying command failures (missing tools, test failures, script errors) at template-evaluation time.","triggerScenarios":"A template invokes exec(command=...) via parse_template/get_tera_v1 and the spawned command exits non-zero (e.g. `exec(command=\"foo --version\")` where foo is missing or fails).","commonSituations":"mise.toml env/template values calling exec on tools not yet installed; PATH differences between shell and mise context; commands that fail intermittently (network checks); typos in the executed command.","solutions":["Run the command from the error's stderr manually and fix the underlying failure.","Ensure the command exists on PATH inside mise (use mise shims or full path).","Make the command tolerant: append `|| true` or `2>/dev/null || echo fallback`.","If output goes to stderr, redirect it (cmd 2>&1) so success path works too."],"exampleFix":"# before\n[env]\nFOO = \"{{ exec(command='possibly-missing-tool --flag') }}\"\n# after\n[env]\nFOO = \"{{ exec(command='possibly-missing-tool --flag 2>/dev/null || echo default') }}\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// tolerate failing exec commands in templates\n[env]\nFOO = \"{{ exec(command='cmd --flag 2>/dev/null || echo fallback') }}\"","preventionTips":["Only call exec() on commands guaranteed present in mise's environment.","Append `|| echo <default>` fallbacks to optional commands.","Test templates with `mise env` before relying on them."],"tags":["templates","tera","exec","shell","exit-code"],"backgroundTag":"command-not-found","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}