{"record":{"id":"ce1958d8c72f5112","repo":"jdx/mise","slug":"failed-ce1958","errorCode":null,"errorMessage":"{} failed","messagePattern":"(.+?) failed","errorType":"exception","errorClass":"eyre::Report","httpStatus":null,"severity":"error","filePath":"src/system/sudo.rs","lineNumber":157,"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":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/jdx/mise/blob/9dcfcaa0dc8747a2577d3270b69bb9d8313b2807/src/system/sudo.rs#L139-L175","documentation":"sudo::run executes an elevated command via sudo (with a pre_exec fchdir restoring the caller's cwd) and checks the exit status; on failure it bails with the full argv, which includes env assignments injected by the wrapper. Interactive callers are expected to hold a sudo timestamp from a prior `sudo -v`, so a failure here means sudoers policy rejected the command or the elevated command itself exited non-zero.","triggerScenarios":"Non-interactive runs using `sudo -n` after the timestamp expired; sudoers rules that deny or do not whitelist the specific command; the privileged bootstrap step failing on a real system error.","commonSituations":"CI/cron without NOPASSWD configured for mise's elevated helper; hardened sudoers whitelists missing one subcommand; privileged apply failing due to underlying system state (disk, permissions).","solutions":["Run `sudo -v` interactively immediately before, or configure NOPASSWD for the elevated helper in sudoers","Copy the printed argv and run it manually to see the real exit status and stderr","Check sudoers covers every privileged subcommand mise invokes","Fix the underlying failure of the elevated command once identified from its output"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before a batch of elevated operations, confirm sudo will not block or deny\nfn elevation_ready() -> Result<()> {\n    let status = Command::new(\"sudo\").arg(\"-n\").arg(\"-v\").status()?;\n    if !status.success() {\n        bail!(\"sudo credentials unavailable; run `sudo -v` interactively first\");\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match sudo::run(&program, &args, &envs) {\n    Err(err) => {\n        let msg = err.to_string();\n        if let Some(argv) = msg.strip_suffix(\" failed\") {\n            // argv names the exact elevated command; re-run it manually to inspect the real failure\n        }\n        return Err(err);\n    }\n    ok => ok,\n}","preventionTips":["Authenticate with `sudo -v` immediately before interactive bootstrap runs","Configure NOPASSWD (or a precise sudoers whitelist) for the elevated helper in CI/cron","Never treat this error as transient: inspect the child command's own failure first"],"tags":["bootstrap","sudo","privileges","subprocess"],"backgroundTag":"sudo-command-failed","analyzedSha":"9dcfcaa0dc8747a2577d3270b69bb9d8313b2807","analyzedAt":"2026-08-17T14:28:50.624Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}