jdx/mise · error
pacman -Qm failed: {}
Error message
pacman -Qm failed: {} What it means
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.
Source
Thrown at src/system/packages/aur.rs:136
}
async fn foreign_packages() -> Result<String> {
let args = ["-Qm"];
debug!("$ pacman {}", args.join(" "));
let output = tokio::process::Command::new("pacman")
.args(args)
.env("LC_ALL", "C")
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
.await?;
let stdout = String::from_utf8_lossy(&output.stdout);
let stderr = String::from_utf8_lossy(&output.stderr);
let no_foreign_packages =
output.status.code() == Some(1) && stdout.trim().is_empty() && stderr.trim().is_empty();
if !output.status.success() && !no_foreign_packages {
bail!("pacman -Qm failed: {}", stderr.trim());
}
Ok(stdout.into_owned())
}
#[async_trait(?Send)]
impl SystemPackageManager for AurManager {
fn name(&self) -> &str {
"aur"
}
fn is_available(&self) -> bool {
cfg!(target_os = "linux")
&& crate::file::which("pacman").is_some()
&& self.helper().is_some()
}
fn unavailable_reason(&self) -> String {
if !cfg!(target_os = "linux") {View on GitHub (pinned to afd2eddd3a)
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.
Example fix
// before $ mise install aur:yay Error: pacman -Qm failed: error: could not open database // after: repair the pacman local database, then retry $ sudo pacman -Dk # or restore local/ from backup $ mise install aur:yay
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure pacman's foreign-package query works before using the aur backend
const probe = await run('pacman', ['-Qm']);
if (probe.code !== 0 && !(probe.code === 1 && !probe.stdout.trim() && !probe.stderr.trim())) {
throw new Error(`pacman -Qm unhealthy (exit ${probe.code}): ${probe.stderr}`);
} Type guard
function isPacmanQueryFailure(err: unknown): err is & { message: string } {
return err instanceof Error && err.message.startsWith('pacman -Qm failed:');
} Try / catch
try {
await mise.install('aur:yay');
} catch (err) {
if (isPacmanQueryFailure(err)) {
if (/could not open database|corrupt/i.test(err.message)) {
await run('sudo', ['pacman', '-Dk']); // validate/repair local DB, then retry
}
throw err;
}
throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- AUR helpers cannot install a pinned version ('{pkg}')
- AUR packages cannot be built as root; run mise as a non-root
- pacman -T failed: {}
- dpkg-query failed: {}
- pacman cannot install a pinned version ('{p}'): Arch reposit
AI-assisted analysis of jdx/mise@afd2eddd3a (2026-09-09).
Data as JSON: /api/errors/21dd6d99eb0471bd.
Report an issue: GitHub.