Jguer/yay · error

failed to retrieve aur Cache

Error message

failed to retrieve aur Cache: %w

What it means

The graph command creates an AUR metadata cache via metadata.New with WithCacheFilePath(<BuildDir>/aur.json). If initializing that cache (reading/creating the cache file) fails, the error is wrapped with gotext.Get('failed to retrieve aur Cache') and returned from handleCmd. metadata.New returns an error when the cache file exists but is unreadable/corrupt or its directory cannot be used.

Solutions

  1. Delete the corrupt cache file: rm $(yay -Pc 2>/dev/null || echo ~/.cache/yay)/aur.json or the aur.json under the configured BuildDir
  2. Check/fix permissions on BuildDir (chown to the running user)
  3. Recreate BuildDir if missing: mkdir -p <BuildDir>
  4. Reset BuildDir to default (yay config or remove the buildDir option in ~/.config/yay/config.json) and retry

Example fix

// before
$ yay graph
failed to retrieve aur Cache: open /home/u/.cache/yay/aur.json: syntax error / permission denied
// after
$ rm /home/u/.cache/yay/aur.json
$ yay graph   # cache rebuilt from AUR RPC
# or programmatically guard:
if err := os.Remove(filepath.Join(buildDir, "aur.json")); err == nil { log.Println("stale aur cache removed; retrying") }
Defensive patterns

Strategy: try-catch

Validate before calling

cachePath := filepath.Join(cfg.BuildDir, "aur.json")
if fi, err := os.Stat(cachePath); err == nil {
    if _, e := os.ReadFile(cachePath); e != nil { os.Remove(cachePath) } // unreadable/corrupt → drop
}
if err := os.MkdirAll(cfg.BuildDir, 0o755); err != nil { return err }

Try / catch

aurCache, err := metadata.New(metadata.WithCacheFilePath(cachePath))
if err != nil {
    log.Printf("aur cache unusable (%v); removing and retrying", err)
    _ = os.Remove(cachePath)
    aurCache, err = metadata.New(metadata.WithCacheFilePath(cachePath))
    if err != nil { return err }
}

Prevention

When it happens

Trigger: Running `yay graph` (main → handleCmd) when cfg.BuildDir points to a non-existent or unwritable directory, aur.json exists but is corrupted (bad JSON/truncated), or filesystem permission errors prevent reading/creating the cache file.

Common situations: Stale/partial aur.json left by a crash or interrupt; BuildDir moved or cleaned while cache path still configured; running yay as different users (root vs user) causing permission mismatch on the cache file.

Related errors


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

Appendix: source

Thrown at pkg/cmd/graph/main.go:46

	if errP := cfg.ParseCommandLine(cmdArgs); errP != nil {
		return errP
	}

	run, err := runtime.NewRuntime(cfg, cmdArgs, "1.0.0")
	if err != nil {
		return err
	}

	dbExecutor, err := ialpm.NewExecutor(run.PacmanConf, logger)
	if err != nil {
		return err
	}

	aurCache, err := metadata.New(
		metadata.WithCacheFilePath(
			filepath.Join(cfg.BuildDir, "aur.json")))
	if err != nil {
		return fmt.Errorf("%s: %w", gotext.Get("failed to retrieve aur Cache"), err)
	}

	grapher := dep.NewGrapher(dbExecutor, aurCache, true, settings.NoConfirm,
		cmdArgs.ExistsDouble("d", "nodeps"), false, false,
		run.Logger.Child("grapher"))

	return graphPackage(context.Background(), grapher, cmdArgs.Targets)
}

func main() {
	fallbackLog := text.NewLogger(os.Stdout, os.Stderr, os.Stdin, false, "fallback")
	if err := handleCmd(fallbackLog); err != nil {
		fallbackLog.Errorln(err)
		os.Exit(1)
	}
}

func graphPackage(

View on GitHub (pinned to 328f4b4939)