{"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/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/apt.rs#L32-L68","documentation":"The apt backend shells out to `apt-cache policy` to decide whether a package is installable. apt-cache reports unknown package names on stderr without failing, so a nonzero exit status means apt-cache itself failed to run, and mise raises the trimmed stderr.","triggerScenarios":"`apt-cache policy` exits nonzero — e.g. apt package lists are corrupt, /var/lib/apt is broken, or apt-cache is missing/unusable on the host.","commonSituations":"Broken or never-initialized apt lists (no `apt-get update` ever run) in containers; corrupted /var/lib/apt/lists in a slim Docker image; running where apt exists but its cache directory is unreadable.","solutions":["Read the stderr embedded in the message","Run `apt-get update` to (re)build package lists","Verify manually: apt-cache policy <package>","If the host is not Debian-based, remove apt from mise's bootstrap package managers"],"exampleFix":"// before\n# container missing lists\napt-cache policy curl  # exits nonzero\n// after\nRUN apt-get update && mise install","handlingStrategy":"try-catch","validationCode":"apt-cache policy >/dev/null 2>&1 || (apt-get update && apt-cache policy >/dev/null) || echo 'apt-cache unusable'","typeGuard":null,"tryCatchPattern":"if let Err(e) = available(pkg) {\n    if e.to_string().contains(\"apt-cache policy failed\") {\n        run(\"apt-get update\");\n        retry(pkg)?;\n    }\n}","preventionTips":["Run apt-get update when building Debian/Ubuntu images that use mise","Don't strip /var/lib/apt/lists in images that bootstrap via apt","Smoke-test apt-cache in CI before running mise bootstrap"],"tags":["apt","debian","package-manager","command-failed"],"backgroundTag":"http-error-response","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"}