{"record":{"id":"ce1958d8c72f5112","repo":"jdx/mise","slug":"failed-ce1958","errorCode":null,"errorMessage":"{} failed","messagePattern":"(.+?) failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/sudo.rs","lineNumber":180,"sourceCode":"    let raw = dir.as_fd().as_raw_fd();\n    let mut cmd = Command::new(&argv[0]);\n    cmd.args(&argv[1..]);\n    // SAFETY: `fchdir` is async-signal-safe and only alters the child's working\n    // directory. `raw` stays open in the parent across the spawn, and CLOEXEC\n    // (if set) only takes effect at exec, after pre_exec has run.\n    unsafe {\n        cmd.pre_exec(move || {\n            if nix::libc::fchdir(raw) == -1 {\n                return Err(std::io::Error::last_os_error());\n            }\n            Ok(())\n        });\n    }\n    let status = cmd\n        .status()\n        .wrap_err_with(|| format!(\"failed to run {}\", argv.join(\" \")))?;\n    if !status.success() {\n        bail!(\"{} failed\", argv.join(\" \"));\n    }\n    Ok(())\n}\n\n/// Run an elevated command and capture its output.\n///\n/// Interactive callers authenticate with an inherited `sudo -v` first so a\n/// password prompt is never hidden inside captured stderr. Non-interactive\n/// callers retain [`ensure_elevation_available`]'s fail-fast `sudo -n` check.\npub(crate) fn output(program: &str, args: &[String], envs: &[(String, String)]) -> Result<Output> {\n    let argv = argv_with_env(program, args, envs);\n    let manual_cmd = std::iter::once(\"sudo\".to_string())\n        .chain((!envs.is_empty()).then_some(\"env\".to_string()))\n        .chain(envs.iter().map(|(key, value)| format!(\"{key}={value}\")))\n        .chain(std::iter::once(program.to_string()))\n        .chain(args.iter().cloned())\n        .collect::<Vec<_>>()\n        .join(\" \");","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/sudo.rs#L162-L198","documentation":"mise ran an elevated command via sudo (with `fchdir` into the target directory) and the child process exited with a non-zero status. The error message is the full argument vector that failed; the actual error output was inherited by the terminal (stdio is not captured in `run_in_dir`, so sudo password prompts and the command's own stderr appear directly).","triggerScenarios":"`run_in_dir` spawns `sudo <program> <args>` and `cmd.status()` reports failure — e.g. `sudo mkdir` denied by sudoers, `sudo apt install` failing to fetch packages, or the underlying program exiting non-zero under elevation.","commonSituations":"Sudoers policy not permitting the command for the user; sudo credentials expired and no TTY for the prompt; package manager failures during privileged setup; disk-full or network errors inside the elevated command.","solutions":["Check the command's output printed in the terminal just before the error for the real cause","Run the exact `sudo <program> <args>` shown by `failed to run ...` manually to reproduce","Verify sudoers permits the command (`sudo -l`), and authenticate with `sudo -v` beforehand in non-interactive contexts","Fix the underlying failure (network, disk, package errors) and re-run"],"exampleFix":"// before: failing due to missing sudoers rule\nsudo mise bootstrap install-service\n// after: grant the rule then retry\n// /etc/sudoers.d/mise: youruser ALL=(root) NOPASSWD: /usr/local/bin/mise\nsudo mise bootstrap install-service","handlingStrategy":"try-catch","validationCode":"sudo -n true 2>/dev/null && sudo -l | grep -q <program> && echo \"elevation available\"","typeGuard":null,"tryCatchPattern":"match sudo::run_in_dir(prog, args, dir) { Err(e) if e.ends_with(\"failed\") => inspect_child_output_and_retry(), other => other }","preventionTips":["Run `sudo -v` interactively before non-interactive elevated commands","Add required commands to sudoers (NOPASSWD) for CI environments","Review the command's inherited stderr output before the error line for the root cause"],"tags":["sudo","command-failed","elevation"],"backgroundTag":"git-command-failed","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"}