{"record":{"id":"1ebf40197269f738","repo":"jdx/mise","slug":"winget-list-failed-for","errorCode":null,"errorMessage":"winget list failed for '{}': {}","messagePattern":"winget list failed for '(.+?)': (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/winget.rs","lineNumber":147,"sourceCode":"    match code {\n        Some(0) => {\n            let installed = parse_list_rows(stdout, &request.name);\n            if installed.is_empty() {\n                return Err(eyre::eyre!(\n                    \"winget list succeeded but returned no parseable row for '{}'\",\n                    request.name\n                ));\n            }\n            Ok(package_state(request, &installed))\n        }\n        Some(NO_APPLICATIONS_FOUND) => Ok(PackageState::Missing),\n        _ => {\n            let detail = [stdout.trim(), stderr.trim()]\n                .into_iter()\n                .filter(|part| !part.is_empty())\n                .collect::<Vec<_>>()\n                .join(\"\\n\");\n            bail!(\"winget list failed for '{}': {}\", request.name, detail);\n        }\n    }\n}\n\n/// Queries one package without accepting agreements or changing WinGet state.\nasync fn query_package(request: &PackageRequest) -> Result<PackageStatus> {\n    let args = list_args(request);\n    debug!(\"$ winget {}\", args.join(\" \"));\n    let output = tokio::process::Command::new(\"winget\")\n        .args(args)\n        .stdin(Stdio::null())\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped())\n        .output()\n        .await?;\n    let stdout = String::from_utf8_lossy(&output.stdout);\n    let stderr = String::from_utf8_lossy(&output.stderr);\n    let state = query_state(output.status.code(), &stdout, &stderr, request)?;","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/winget.rs#L129-L165","documentation":"query_state runs `winget list` to determine a package's installed state. When winget exits with an unrecognized/unexpected code, the command's captured stdout/stderr detail is included in this error so the caller can see why winget failed. Query failures are deliberately propagated rather than treated as 'package missing'.","triggerScenarios":"Calling query_package (via query_state) when `winget list --id <pkg>` exits with a non-success, non-accepted code — e.g. winget source unavailable, msstore agreement issues, corrupted winget install, or package id causing a winget error.","commonSituations":"CI container where the winget source (msstore/winget) has never been updated or agreements not accepted; App Installer/winget out of date; restricted Windows environment where winget is disabled; transient source-network failures.","solutions":["Read the detail appended to the error; run the same `winget list` command manually to reproduce","Run `winget source update` (and `winget source reset --force` if sources are broken)","Accept agreements by running `winget list` once interactively and handling prompts","Update the App Installer package (winget) from the Microsoft Store or via `winget upgrade Microsoft.DesktopAppInstaller`"],"exampleFix":"// before\nmise packages status winget:Git.Git\n# winget list failed for 'Git.Git': No package found matching input criteria.\n// after (fix source then retry)\nwinget source update\nmise packages status winget:Git.Git","handlingStrategy":"retry","validationCode":"if !command_exists(\"winget\") { return Err(anyhow!(\"winget unavailable\")); }\nlet probe = Command::new(\"winget\").arg(\"source\").arg(\"list\").output()?;\nif !probe.status.success() { run(\"winget source update\")?; }","typeGuard":"fn winget_healthy(status: Option<i32>) -> bool { status == Some(0) }","tryCatchPattern":"match query_package(&req).await {\n    Err(e) if e.to_string().contains(\"winget list failed\") => {\n        winget_source_update().await?; query_package(&req).await\n    }\n    other => other,\n}","preventionTips":["Run `winget source update` periodically and after first boot in CI images","Update App Installer/winget regularly","Accept source agreements once interactively before automated runs"],"tags":["winget","windows","subprocess","package-manager"],"backgroundTag":"command-not-found","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}