{"record":{"id":"657609661fa77683","repo":"jdx/mise","slug":"dpkg-query-failed","errorCode":null,"errorMessage":"dpkg-query failed: {}","messagePattern":"dpkg-query failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/apt.rs","lineNumber":193,"sourceCode":"        if pkgs.is_empty() {\n            return Ok(vec![]);\n        }\n        let mut args = vec![\n            \"-W\".to_string(),\n            \"-f=${Package}\\\\t${db:Status-Status}\\\\t${Version}\\\\t${Architecture}\\\\n\".to_string(),\n        ];\n        args.extend(pkgs.iter().map(|p| dpkg_name(&p.name).to_string()));\n        debug!(\"$ dpkg-query {}\", args.join(\" \"));\n        let output = tokio::process::Command::new(\"dpkg-query\")\n            .args(&args)\n            .stdin(Stdio::null())\n            .stdout(Stdio::piped())\n            .stderr(Stdio::piped())\n            .output()\n            .await?;\n        // exit 1 just means some packages are unknown to dpkg — they're Missing\n        if !output.status.success() && output.status.code() != Some(1) {\n            bail!(\n                \"dpkg-query failed: {}\",\n                String::from_utf8_lossy(&output.stderr).trim()\n            );\n        }\n        let stdout = String::from_utf8_lossy(&output.stdout);\n        Ok(parse_dpkg_query(&stdout, pkgs))\n    }\n\n    async fn available(&self, names: &[String]) -> Result<Vec<bool>> {\n        if names.is_empty() {\n            return Ok(vec![]);\n        }\n        // apt-cache policy heads every stanza with the *bare* package name, so\n        // `bash:amd64` reports as `bash:` — an arch qualifier cannot be\n        // recovered from a batched result, and matching one by its bare name\n        // would call `bash:arm64` installable whenever any `bash` stanza is\n        // present. Bare names go in one batch; each qualified name gets its own\n        // query, where apt answers by emitting a stanza or nothing at all.","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/apt.rs#L175-L211","documentation":"The apt backend uses `dpkg-query` to check installed package state. dpkg-query exits 1 when some queried packages are simply unknown (treated as 'Missing'), so only other nonzero statuses are errors; mise then raises dpkg-query's stderr.","triggerScenarios":"`dpkg-query` exits with a code other than 0 or 1 — dpkg database corruption, lock contention, or dpkg-query binary broken/missing.","commonSituations":"Interrupted dpkg operation leaving /var/lib/dpkg inconsistent; concurrent package operations holding the dpkg lock; chroot/container with a partial dpkg database.","solutions":["Read the stderr in the message for dpkg's actual complaint","Run `dpkg --configure -a` to repair an interrupted dpkg state","Ensure no other package operation is holding the dpkg lock","Verify manually: dpkg-query -W <package>"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"dpkg-query -W -f='${Status}' dpkg >/dev/null 2>&1 || dpkg --configure -a","typeGuard":null,"tryCatchPattern":"if let Err(e) = installed(pkgs) {\n    if e.to_string().contains(\"dpkg-query failed\") {\n        run(\"dpkg --configure -a\");\n        retry(pkgs)?;\n    }\n}","preventionTips":["Never kill dpkg mid-operation; let it finish","Serialize apt/dpkg operations (no concurrency with mise bootstrap)","Check dpkg health in container entrypoints before bootstrap"],"tags":["dpkg","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"}