{"record":{"id":"d4228c8a03181026","repo":"jdx/mise","slug":"display-program-display-args-failed-exit-code","errorCode":null,"errorMessage":"{display_program} {display_args} failed: exit code {}\n{}","messagePattern":"(.+?) (.+?) failed: exit code (.+?)\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd.rs","lineNumber":2034,"sourceCode":"    let display_program = program.to_string_lossy();\n    let display_args = args.join(\" \");\n    debug!(\"$ {display_program} {display_args}\");\n\n    let output = tokio::process::Command::new(program)\n        .args(args)\n        .env_clear()\n        .envs(env)\n        .stdin(Stdio::null())\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped())\n        .kill_on_drop(true)\n        .output()\n        .await\n        .wrap_err_with(|| format!(\"failed to execute command: {display_program} {display_args}\"))?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        bail!(\n            \"{display_program} {display_args} failed: exit code {}\\n{}\",\n            output.status.code().unwrap_or(-1),\n            stderr.trim()\n        );\n    }\n\n    let stdout = String::from_utf8(output.stdout)\n        .wrap_err_with(|| format!(\"{display_program} produced invalid UTF-8 output\"))?;\n    Ok(stdout.trim_end().to_string())\n}\n\n/// Like [`cmd_read_async`] but **inherits** the current process environment,\n/// only adding the provided extra variables on top.\n///\n/// Use this for core plugins that need the ambient PATH / locale / etc.\npub(crate) async fn cmd_read_async_inherited_env<I, K, V>(\n    program: &str,\n    args: &[&str],","sourceCodeStart":2016,"sourceCodeEnd":2052,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/cmd.rs#L2016-L2052","documentation":"A helper command executed by cmd_read_async failed with a non-zero exit code; mise wraps the program, its arguments, the exit code, and the command's trimmed stderr into one error. This is the generic 'external command failed' path for async command reads used across backends.","triggerScenarios":"Raised at src/cmd.rs:2034 in cmd_read_async when `output.status.success()` is false after `Command::output().await`; the error text embeds `exit code N` (or -1 if killed by a signal) plus the child's stderr.","commonSituations":"Backend helper invocations failing — e.g. `git` not finding a repo, a version-listing tool not installed or on PATH, curl/gh failing with auth or network errors, or scripts exiting non-zero due to bad configuration.","solutions":["Read the stderr embedded in the error message — it contains the child's actual failure reason.","Verify the failing program is installed and on PATH inside mise's environment (`mise x -- which <prog>`).","Fix the underlying cause (credentials, network, bad args, missing repo/file).","If the command legitimately fails sometimes, handle the error at the call site instead of propagating it."],"exampleFix":"// before: opaque failure because git runs outside the repo\nlet out = cmd_read_async(\"git\", [\"rev-parse\", \"HEAD\"]).await?;\n\n// after: run with the correct working directory / check preconditions\nlet out = cmd(\"git\").args([\"rev-parse\", \"HEAD\"]).current_dir(project_root).read_async().await?;","handlingStrategy":"try-catch","validationCode":"// Confirm the helper program exists and works before invoking it:\ncommand -v git >/dev/null 2>&1 || { echo \"git not on PATH\" >&2; exit 127; }\ngit rev-parse --is-inside-work-tree >/dev/null 2>&1 || { echo \"not a git repo\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"match cmd_read_async(program, args).await {\n    Err(e) => {\n        // error text already embeds exit code + stderr from the child\n        eprintln!(\"helper failed: {e}\");\n        // inspect e chain / stderr for the root cause before retrying\n    }\n    Ok(out) => out,\n}","preventionTips":["Always read the stderr embedded in the error — it names the real cause.","Verify helper tools and their working directory/env before automated use.","Set explicit credentials (GH_TOKEN etc.) for network-touching helpers in CI.","Prefer helpers that report failure via exit code plus a clear stderr message."],"tags":["subprocess","exit-code","stderr"],"backgroundTag":"command-exit-nonzero","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}