Jguer/yay · error

problem importing keys

Error message

problem importing keys

What it means

importKeys shells out to gpg (gpg --recv-keys <keys...>) to fetch the PGP keys needed to verify a source package, and wraps any non-zero exit in this generic error. It means gpg could not receive one or more of the requested keys from the configured keyservers.

Solutions

  1. Import the key manually to see the real gpg error: gpg --recv-keys <KEYID>, then re-run the build.
  2. Point gpg at a reliable keyserver, e.g. add keyserver hkp://keyserver.ubuntu.com:80 to ~/.gnupg/dirmngr.conf and restart dirmngr.
  3. Check network access to keyserver ports (11371/hkp or 80); retry if the keyserver was temporarily down.
  4. Verify the key ID in the PKGBUILD's validpgpkeys is correct and still published.

Example fix

// before (keyserver unreachable)
gpg --recv-keys A5E9D918BCF8F335  # times out -> "problem importing keys"
// after (~/.gnupg/dirmngr.conf)
keyserver hkp://keyserver.ubuntu.com:80
# then: gpg --recv-keys A5E9D918BCF8F335
Defensive patterns

Strategy: retry

Validate before calling

// pre-check key availability
for _, key := range keys {
    if err := exec.Command("gpg", "--list-keys", key).Run(); err != nil {
        // key not in keyring yet; ensure network/keyserver reachable
    }
}

Try / catch

err := pgp.CheckPgpKeys(ctx, logger, srcinfos, cmdBuilder, noConfirm)
if err != nil && strings.Contains(err.Error(), "problem importing keys") {
    // surface hint: run gpg --recv-keys <KEYID> manually / check keyserver
    return fmt.Errorf("%w: check network and keyserver config", err)
}

Prevention

When it happens

Trigger: CheckPgpKeys -> importKeys when cmdBuilder.Show on the built gpg --recv-keys command returns an error: keys already present plus another gpg failure, keyserver unreachable, key not found on any keyserver, or malformed key IDs.

Common situations: Building AUR packages whose makepkg validpgpkeys are not in the local keyring; firewalled/offline environments blocking hkp port 11371; keyservers (keyserver.ubuntu.com, pool.sks-keyservers.net) being flaky; key IDs that were revoked or never published.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of Jguer/yay@328f4b4939 (2026-09-07). Data as JSON: /api/errors/702393854cffb1e9. Report an issue: GitHub.

Appendix: source

Thrown at pkg/sync/srcinfo/pgp/keys.go:100

	if err != nil {
		return nil, err
	}

	logger.Println("\n", str)

	if logger.ContinueTask(gotext.Get("Import?"), true, noConfirm) {
		return problematic.toSlice(), importKeys(ctx, logger, cmdBuilder, problematic.toSlice())
	}

	return problematic.toSlice(), nil
}

// importKeys tries to import the list of keys specified in its argument.
func importKeys(ctx context.Context, logger *text.Logger, cmdBuilder GPGCmdBuilder, keys []string) error {
	logger.OperationInfoln(gotext.Get("Importing keys with gpg..."))

	if err := cmdBuilder.Show(cmdBuilder.BuildGPGCmd(ctx, append([]string{"--recv-keys"}, keys...)...)); err != nil {
		return errors.New(gotext.Get("problem importing keys"))
	}

	return nil
}

// formatKeysToImport receives a set of keys and returns a string containing the
// question asking the user wants to import the problematic keys.
func formatKeysToImport(logger *text.Logger, keys pgpKeySet) (string, error) {
	if len(keys) == 0 {
		return "", errors.New(gotext.Get("no keys to import"))
	}

	var buffer bytes.Buffer

	buffer.WriteString(logger.SprintOperationInfo(gotext.Get("PGP keys need importing:")))

	for key, bases := range keys {
		pkglist := ""

View on GitHub (pinned to 328f4b4939)