{"record":{"id":"21dd6d99eb0471bd","repo":"jdx/mise","slug":"pacman-qm-failed","errorCode":null,"errorMessage":"pacman -Qm failed: {}","messagePattern":"pacman -Qm failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/packages/aur.rs","lineNumber":136,"sourceCode":"}\n\nasync fn foreign_packages() -> Result<String> {\n    let args = [\"-Qm\"];\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()\n        .await?;\n    let stdout = String::from_utf8_lossy(&output.stdout);\n    let stderr = String::from_utf8_lossy(&output.stderr);\n    let no_foreign_packages =\n        output.status.code() == Some(1) && stdout.trim().is_empty() && stderr.trim().is_empty();\n    if !output.status.success() && !no_foreign_packages {\n        bail!(\"pacman -Qm failed: {}\", stderr.trim());\n    }\n    Ok(stdout.into_owned())\n}\n\n#[async_trait(?Send)]\nimpl SystemPackageManager for AurManager {\n    fn name(&self) -> &str {\n        \"aur\"\n    }\n\n    fn is_available(&self) -> bool {\n        cfg!(target_os = \"linux\")\n            && crate::file::which(\"pacman\").is_some()\n            && self.helper().is_some()\n    }\n\n    fn unavailable_reason(&self) -> String {\n        if !cfg!(target_os = \"linux\") {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/aur.rs#L118-L154","documentation":"When resolving foreign (AUR) packages, `AurManager::installed` calls `foreign_packages()`, which runs `pacman -Qm` to list explicitly-installed foreign packages. Exit code 1 with empty stdout and stderr is the documented 'no foreign packages' case and is tolerated; any other non-zero exit bubbles the trimmed stderr up as this error. It means the pacman database query itself failed rather than simply having no results.","triggerScenarios":"resolve_foreign_packages -> foreign_packages() spawns `LC_ALL=C pacman -Qm`; pacman exits non-zero (and not the tolerated 1-with-empty-output case). Triggered by a corrupt pacman local database, pacman failing to open /var/lib/pacman, or pacman emitting real errors to stderr even with exit 1.","commonSituations":"Arch/Manjaro systems with a corrupted or partially-upgraded local DB, running as a user who cannot read the pacman database, interrupted `pacman -Syu` leaving the DB locked or inconsistent, or pacman wrapper configurations that break plain pacman invocation.","solutions":["Inspect the stderr embedded in the error; if it reports a corrupt database, repair with `sudo pacman -Dk` (check) and restore from /var/lib/pacman/local backup if needed.","If a lock is reported, wait for any running pacman/yay/paru process to finish and remove a stale /var/lib/pacman/db.lck only when pacman is not running.","Verify `pacman -Qm` runs successfully in a shell as the same user; fix permissions or environment issues it reports.","Run `sudo pacman -Syu` to bring the database and system to a consistent state, then retry the mise command."],"exampleFix":"// before\n$ mise install aur:yay\nError: pacman -Qm failed: error: could not open database\n\n// after: repair the pacman local database, then retry\n$ sudo pacman -Dk   # or restore local/ from backup\n$ mise install aur:yay","handlingStrategy":"try-catch","validationCode":"// ensure pacman's foreign-package query works before using the aur backend\nconst probe = await run('pacman', ['-Qm']);\nif (probe.code !== 0 && !(probe.code === 1 && !probe.stdout.trim() && !probe.stderr.trim())) {\n  throw new Error(`pacman -Qm unhealthy (exit ${probe.code}): ${probe.stderr}`);\n}","typeGuard":"function isPacmanQueryFailure(err: unknown): err is & { message: string } {\n  return err instanceof Error && err.message.startsWith('pacman -Qm failed:');\n}","tryCatchPattern":"try {\n  await mise.install('aur:yay');\n} catch (err) {\n  if (isPacmanQueryFailure(err)) {\n    if (/could not open database|corrupt/i.test(err.message)) {\n      await run('sudo', ['pacman', '-Dk']); // validate/repair local DB, then retry\n    }\n    throw err;\n  }\n  throw err;\n}","preventionTips":["Keep the pacman local database consistent: always finish interrupted `-Syu` runs and run `pacman -Dk` after crashes.","Never delete /var/lib/pacman/db.lck while a pacman/yay/paru process may be running.","Avoid mixing multiple AUR helpers or partial upgrades (`-Sy` without `-u`) that leave the DB inconsistent.","Smoke-test `pacman -Qm` in provisioning scripts before relying on mise's aur backend."],"tags":["arch-linux","pacman","aur","package-manager","external-command"],"backgroundTag":"database-query-failed","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}