{"record":{"id":"fddd60bd85f59aa4","repo":"jdx/mise","slug":"pacman-q-failed","errorCode":null,"errorMessage":"pacman -Q failed: {}","messagePattern":"pacman -Q failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/pacman.rs","lineNumber":344,"sourceCode":"                .strip_suffix(\"' was not found\")\n        })\n        .filter(|name| names.iter().any(|requested| requested == name))\n        .collect::<HashSet<_>>();\n    let only_missing = !missing.is_empty()\n        && stderr.lines().all(|line| {\n            line.trim().is_empty()\n                || missing.iter().any(|name| {\n                    line == format!(\"error: package '{name}' was not found\")\n                        || line\n                            == format!(\n                                \"warning: '{name}' is a file, you might want to use -p/--file.\"\n                            )\n                })\n        });\n    let valid_result = (output.status.success() && stderr.is_empty())\n        || (output.status.code() == Some(1) && only_missing);\n    if !valid_result {\n        bail!(\"pacman -Q failed: {}\", stderr.trim());\n    }\n    Ok(String::from_utf8_lossy(&output.stdout).into_owned())\n}\n\nasync fn pacman_deptest(names: &[String]) -> Result<String> {\n    if names.is_empty() {\n        return Ok(String::new());\n    }\n    let mut args = vec![\"-T\", \"--\"];\n    args.extend(names.iter().map(String::as_str));\n    debug!(\"$ pacman {}\", args.join(\" \"));\n    let output = tokio::process::Command::new(\"pacman\")\n        .args(&args)\n        .env(\"LC_ALL\", \"C\")\n        .stdin(Stdio::null())\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped())\n        .output()","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/pacman.rs#L326-L362","documentation":"mise's pacman backend runs `pacman -Q` to query installed packages and only accepts exit 0, or exit 1 when the query was explicitly for possibly-missing packages. Any other combination (non-zero status with stderr output, or exit 1 outside the tolerated case) means the query itself failed rather than simply reporting a package as absent, so mise aborts with pacman's stderr text. This keeps silent pacman failures (corrupt local db, bad arguments, lock issues) from being misread as 'package not installed'.","triggerScenarios":"Calling the backend's `installed` (package status check) or `upgrade` path when `pacman -Q <pkg>` exits with a code other than 0, or exits 1 with stderr non-empty in a context where missing packages are not tolerated (only_missing == false). Also triggered from test_pacman_query_file_advisory scenarios where the file-based query returns an unexpected status.","commonSituations":"pacman's database lock is held by another pacman process; the local database is corrupt ('error: could not open local database'); a partial pacman upgrade left the db inconsistent; running inside a container/sandbox where /var/lib/pacman is missing or read-only; a wrapper or alias intercepts pacman and returns a non-standard exit code.","solutions":["Run `pacman -Q <package>` manually to see the underlying stderr and fix pacman itself (e.g. remove a stale /var/lib/pacman/db.lck, run `pacman -D --asdeps` repairs or re-init the db).","Ensure no other pacman/pikaur/yay process is running when mise queries packages.","Verify you are on an Arch-based system where /var/lib/pacman/local exists; mise's pacman backend is not meant for non-Arch hosts.","If a package genuinely is not installed, this error should not appear — report it; the caller should have tolerated exit 1 for missing packages."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-check pacman health before relying on mise package queries\nconst { code, stderr } = await sh(\"pacman -Q 2>&1; echo $?\");\nif (code !== 0 && !/no targets specified|package .* was not found/.test(stderr)) {\n  throw new Error(`pacman unusable: ${stderr.trim()} (stale db.lck? corrupt local db?)`);\n}","typeGuard":null,"tryCatchPattern":"try { await miseInstallPacman(pkgs) } catch (e) { if (String(e).includes('pacman -Q failed')) { const stderr = e.message.split(': ').slice(1).join(': '); console.error('Fix pacman first:', stderr); } else throw e; }","preventionTips":["Keep pacman healthy: no concurrent pacman processes and no stale /var/lib/pacman/db.lck.","Use mise's pacman backend only on Arch-based systems with an initialized local database.","Before scripted installs, run `pacman -Q <pkg>` once interactively to confirm the db is readable.","Avoid wrappers/aliases named pacman that alter exit codes."],"tags":["pacman","package-manager","external-command","arch-linux"],"backgroundTag":"pacman-query-failed","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"}