{"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/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/winget.rs#L170-L206","documentation":"winget was invoked (install, uninstall, upgrade, or source-related action) for packages, and the process exited with a code not in the accepted list for that action, so the wrapper bails. This is a pass-through of winget's own failure status; the underlying cause (network, package not found, agreement needed) is in winget's stderr, which is streamed to the terminal.","triggerScenarios":"run_winget spawns `winget <action> ...` with inherited stdout/stderr; after awaiting status, command_succeeded(status.code(), accepted_exit_codes) returns false — e.g. winget exits 0x8A15002B (no package found), a nonzero installer exit code, or any exit code outside the accepted list passed by the caller.","commonSituations":"Installing/upgrading a Windows package whose ID is misspelled or no longer in the winget repository; winget lacking admin elevation for machine-wide installs; winget source out of date; the installer itself failing (corrupt download, blocked by policy/antivirus).","solutions":["Read the winget output above the error in the terminal (stderr is inherited) and address the specific winget failure code.","Run `winget source update` and retry; stale source data is a common cause.","Verify the exact package ID with `winget search <name>` and correct the package list.","Rerun from an elevated shell if the package requires machine-wide installation.","Retry later if winget reports a transient network/service error."],"exampleFix":"// before (package id wrong)\npackages = [\"microsof.vscode\"]\n// after\npackages = [\"Microsoft.VisualStudioCode\"]","handlingStrategy":"try-catch","validationCode":"// Windows: verify package id resolves before running\nconst id = pkg;\nconst search = spawnSync('winget', ['search', '--exact', id]);\nif (search.status !== 0) throw new Error(`unknown winget package: ${id}`);","typeGuard":null,"tryCatchPattern":"try {\n  await runPackages(pkgs);\n} catch (e) {\n  if (String(e).includes('winget')) {\n    console.error('winget failed; see stderr above. Try: winget source update, or fix the package id.');\n  }\n  throw e;\n}","preventionTips":["Validate package IDs with `winget search --exact` before batch installs.","Run elevated shells for machine-wide packages.","Keep winget/App Installer updated and run `winget source update` periodically.","Capture winget stderr — it contains the authoritative failure code."],"tags":["windows","winget","package-manager","external-command"],"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"}