{"record":{"id":"2b6122e159fe440a","repo":"jdx/mise","slug":"apt-cache-policy-failed","errorCode":null,"errorMessage":"apt-cache policy failed: {}","messagePattern":"apt-cache policy failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/apt.rs","lineNumber":50,"sourceCode":"    /// holding an arch-qualified name must query it alone.\n    async fn policy_installable(&self, args: &[&str]) -> Result<std::collections::HashSet<String>> {\n        debug!(\"$ apt-cache policy {}\", args.join(\" \"));\n        let output = tokio::process::Command::new(\"apt-cache\")\n            .arg(\"policy\")\n            .args(args)\n            // apt translates the stanza labels this parses, so pin the locale\n            // rather than reading \"Kandidat:\" as an unavailable package\n            .env(\"LC_ALL\", \"C\")\n            .env(\"LANGUAGE\", \"C\")\n            .stdin(Stdio::null())\n            .stdout(Stdio::piped())\n            .stderr(Stdio::piped())\n            .output()\n            .await?;\n        // unknown names are reported on stderr and do not fail the command,\n        // so a nonzero status means apt-cache itself could not run\n        if !output.status.success() {\n            bail!(\n                \"apt-cache policy failed: {}\",\n                String::from_utf8_lossy(&output.stderr).trim()\n            );\n        }\n        Ok(parse_apt_cache_policy(&String::from_utf8_lossy(\n            &output.stdout,\n        )))\n    }\n\n    fn update(&self, opts: &InstallOpts) -> Result<()> {\n        let args = vec![\"update\".to_string()];\n        if opts.dry_run {\n            miseprintln!(\n                \"{}\",\n                sudo::argv_with_env(\"apt-get\", &args, &debian_frontend()).join(\" \")\n            );\n            return Ok(());\n        }","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/apt.rs#L32-L68","documentation":"The apt backend calls `apt-cache policy` to check whether a package is installable (available()). Unknown package names are reported on stderr without failing the command, so a nonzero exit status means apt-cache itself failed to run, and src/system/packages/apt.rs:50 bails with the trimmed stderr.","triggerScenarios":"Calling available()/policy_installable() for apt packages when `apt-cache policy <pkgs>` exits nonzero: apt-cache missing or broken, corrupted apt lists, or a dpkg/apt configuration error preventing apt-cache from starting.","commonSituations":"Running on a Debian/Ubuntu system with a broken or never-populated /var/lib/apt/lists; a misconfigured apt sources file; running inside a minimal container where apt is installed but its cache was cleaned; PATH or sandboxing issues preventing apt-cache from executing properly.","solutions":["Read the stderr detail in the message and fix the apt issue it reports (e.g. rebuild lists with `apt-get update`)","Run `apt-cache policy <package>` manually to reproduce and see the full error","Repair apt configuration: check /etc/apt/sources.list* validity and run `apt-get -f install` / `dpkg --configure -a` if dpkg state is broken","Ensure apt/dpkg are correctly installed before using the apt package manager (skip it on non-Debian systems)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure apt-cache works before using the apt manager\ncommand -v apt-cache >/dev/null || echo \"apt-cache missing\"\napt-cache policy >/dev/null 2>&1 || echo \"apt-cache broken — run apt-get update\"","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().starts_with(\"apt-cache policy failed:\") => {\n        // treat apt availability as unknown; repair apt (apt-get update) or skip apt packages\n    }\n    r => r?,\n}","preventionTips":["Run `apt-get update` before tooling that queries apt-cache policy, especially in fresh containers","Validate /etc/apt/sources.list* after edits; broken sources can break apt-cache itself","Skip or guard apt package entries on non-Debian systems where apt-cache is absent or broken"],"tags":["apt","package-manager","subprocess","debian"],"backgroundTag":"http-request-failed","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"}