{"record":{"id":"a8ac52d7b507e7a4","repo":"jdx/mise","slug":"winget-action-failed-with-status","errorCode":null,"errorMessage":"winget {action} failed with {status}","messagePattern":"winget (.+?) failed with (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/winget.rs","lineNumber":188,"sourceCode":"}\n\n/// Returns whether an exit code is successful for the current operation.\nfn command_succeeded(code: Option<i32>, accepted_exit_codes: &[i32]) -> bool {\n    code == Some(0) || code.is_some_and(|code| accepted_exit_codes.contains(&code))\n}\n\n/// Runs WinGet and accepts only zero plus explicitly allowed no-op codes.\nasync fn run_winget(args: &[String], action: &str, accepted_exit_codes: &[i32]) -> Result<()> {\n    debug!(\"$ winget {}\", args.join(\" \"));\n    let status = tokio::process::Command::new(\"winget\")\n        .args(args)\n        .stdin(Stdio::null())\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .await?;\n    if !command_succeeded(status.code(), accepted_exit_codes) {\n        bail!(\"winget {action} failed with {status}\");\n    }\n    Ok(())\n}\n\n/// Applies a WinGet command to each requested package in order.\nasync fn run_packages(\n    command: &str,\n    pkgs: &[PackageRequest],\n    dry_run: bool,\n    accepted_exit_codes: &[i32],\n) -> Result<()> {\n    for pkg in pkgs {\n        let args = package_args(command, pkg);\n        if dry_run {\n            miseprintln!(\"winget {}\", args.join(\" \"));\n        } else {\n            run_winget(\n                &args,","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/winget.rs#L170-L206","documentation":"run_winget executes a winget action (e.g. source refresh via refresh, or per-package install/upgrade/uninstall via run_packages) with output inherited, and checks the resulting exit status against accepted exit codes. If the status isn't accepted, this error reports the action and status. Certain winget non-zero codes (like reboot-required) can be pre-accepted via accepted_exit_codes.","triggerScenarios":"Calling refresh or run_packages when a winget command (install/upgrade/uninstall/source update) exits with a failing code not in accepted_exit_codes — e.g. installer failure, hash mismatch, requires-elevation, or network error during download.","commonSituations":"winget install needs administrator rights (run from non-elevated shell); download failed or source unreachable; package installer returned its own error code; reboot-required exit codes not included in accepted_exit_codes.","solutions":["Run the same winget command manually to see the interactive output and exact failure reason","If the failing code is benign (e.g. reboot required), update the accepted_exit_codes list for that action","Elevate the shell (admin) if the failure is access-denied during install","Run `winget source update` and retry if the failure was a source/network issue"],"exampleFix":"// before\nmise packages install winget:Git.Git\n# winget install failed with exit code 1978335189 (requires elevation)\n// after: run terminal as administrator\nmise packages install winget:Git.Git","handlingStrategy":"try-catch","validationCode":"let probe = Command::new(\"winget\").args([\"--info\"]).status()?;\nif !probe.success() { /* winget broken or needs elevation */ }","typeGuard":"fn winget_action_ok(status: ExitStatus, accepted: &[i32]) -> bool {\n    status.success() || accepted.contains(&status.code().unwrap_or(-1))\n}","tryCatchPattern":"match run_packages(&pkgs, \"install\").await {\n    Err(e) if e.to_string().contains(\"failed with\") => {\n        if requires_elevation(&e) { rerun_elevated().await } else { return Err(e) }\n    }\n    other => other,\n}","preventionTips":["Run package installs from an elevated shell when installers require admin rights","Pre-list accepted benign exit codes (e.g. reboot-required) for winget actions","Keep winget sources updated so downloads don't fail mid-install"],"tags":["winget","windows","exit-code","subprocess"],"backgroundTag":"http-error-status","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"}