{"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":141,"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 install(&self, pkgs: &[PackageRequest], opts: &InstallOpts) -> Result<()> {\n        if opts.update || self.lists_missing() {\n            self.update(opts)?;\n        }\n        // `--` keeps package operands from ever being parsed as apt-get\n        // options; pins render to apt's native name=version syntax and\n        // name:arch qualifiers pass through in the name\n        let mut args = vec![\"install\".to_string(), \"-y\".to_string(), \"--\".to_string()];\n        args.extend(pkgs.iter().map(|p| match &p.version {\n            Some(v) => format!(\"{}={v}\", p.name),","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/jdx/mise/blob/9dcfcaa0dc8747a2577d3270b69bb9d8313b2807/src/system/packages/apt.rs#L123-L159","documentation":"mise's Debian/Ubuntu (apt) backend shells out to `dpkg-query` to classify requested packages as installed or missing. Exit code 1 is expected and tolerated (it just means some packages are unknown to dpkg, so they are reported Missing); this error fires for any other nonzero exit — dpkg-query failed structurally (locked or malformed database, missing binary, permission problem) and the result is unusable.","triggerScenarios":"Running mise package operations on Debian/Ubuntu when `dpkg-query` exits with a code other than 0 or 1: another apt/dpkg process holds /var/lib/dpkg locks mid-run, /var/lib/dpkg/status is corrupted, or dpkg is absent/broken in a hand-rolled minimal container.","commonSituations":"CI base images where `dpkg --configure -a` was never run; apt interrupted by a killed pipeline leaving dpkg dirty; concurrent `apt-get install` during mise bootstrap; containers where /var/lib/dpkg was partially removed.","solutions":["Run the same query manually: `dpkg-query -W <package>` and read the stderr shown in the message","Clear dpkg's dirty state: `sudo dpkg --configure -a` then `sudo apt-get -f install`","Check for concurrent apt/dpkg processes holding locks (`ps aux | grep -E 'apt|dpkg'`) and let them finish","In stripped images without a working dpkg, don't declare apt packages in mise; install them via the Dockerfile"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"async fn dpkg_query_ok() -> bool {\n    tokio::process::Command::new(\"dpkg-query\")\n        .args([\"-W\", \"dpkg\"])\n        .stdin(std::process::Stdio::null())\n        .stdout(std::process::Stdio::null())\n        .stderr(std::process::Stdio::piped())\n        .output()\n        .await\n        .map(|o| o.status.success() || o.status.code() == Some(1))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"Catch errors matching \"dpkg-query failed\" and retry after a short backoff (dpkg lock contention is transient); if it persists, direct the user to run `dpkg --configure -a` rather than treating packages as installed or missing.","preventionTips":["Finish or clear in-flight apt/dpkg operations before running mise bootstrap","Run `dpkg --configure -a` in Dockerfiles after installing packages","Don't strip /var/lib/dpkg from minimal images if you want apt integration"],"tags":["debian","ubuntu","apt","dpkg","mise","package-manager"],"backgroundTag":"package-manager-query-failed","analyzedSha":"9dcfcaa0dc8747a2577d3270b69bb9d8313b2807","analyzedAt":"2026-08-17T14:28:50.624Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}