{"record":{"id":"25f504c8a3b72dcb","repo":"Jguer/yay","slug":"s-w-25f504","errorCode":null,"errorMessage":"%s %w","messagePattern":"%s %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/menus/diff_menu.go","lineNumber":152,"sourceCode":"// Return whether or not we have reviewed a diff yet. It checks for the existence of\n// AUR_SEEN in the git ref-list.\nfunc gitHasLastSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) bool {\n\t_, _, err := cmdBuilder.Capture(\n\t\tcmdBuilder.BuildGitCmd(ctx,\n\t\t\tdir, \"rev-parse\", \"--quiet\", \"--verify\", gitDiffRefName))\n\n\treturn err == nil\n}\n\n// Returns the last reviewed hash. If AUR_SEEN exists it will return this hash.\n// If it does not it will return empty tree as no diff have been reviewed yet.\nfunc getLastSeenHash(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) (string, error) {\n\tif gitHasLastSeenRef(ctx, cmdBuilder, dir) {\n\t\tstdout, stderr, err := cmdBuilder.Capture(\n\t\t\tcmdBuilder.BuildGitCmd(ctx,\n\t\t\t\tdir, \"rev-parse\", gitDiffRefName))\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"%s %w\", stderr, err)\n\t\t}\n\n\t\tlines := strings.Split(stdout, \"\\n\")\n\n\t\treturn lines[0], nil\n\t}\n\n\treturn gitEmptyTree, nil\n}\n\n// Update the AUR_SEEN ref to HEAD. We use this ref to determine which diff were\n// reviewed by the user.\nfunc gitUpdateSeenRef(ctx context.Context, cmdBuilder exe.ICmdBuilder, dir string) error {\n\t_, stderr, err := cmdBuilder.Capture(\n\t\tcmdBuilder.BuildGitCmd(ctx,\n\t\t\tdir, \"update-ref\", gitDiffRefName, \"HEAD\"))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%s %w\", stderr, err)","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/Jguer/yay/blob/328f4b4939fb35f38c2f7c7ce3b8638a839bafa5/pkg/menus/diff_menu.go#L134-L170","documentation":"getLastSeenHash wraps the failure of `git rev-parse <gitDiffRefName>` by concatenating git's stderr with the exec error via fmt.Errorf(\"%s %w\", stderr, err). This ref stores the commit hash last shown to the user for PKGBUILD diffs; when it cannot be resolved the diff menu cannot compute what changed. The %w wrap keeps the underlying exec error inspectable.","triggerScenarios":"getLastSeenHash runs when gitHasLastSeenRef says the ref exists, but the subsequent `git rev-parse` of that ref fails (ref deleted between the check and the call, corrupted ref file, git repo removed mid-operation, git binary unavailable).","commonSituations":"Race where another yakuake/instance or `git gc` prunes refs/has-been-reviewed while the diff menu runs; package dir replaced by a fresh non-git download between check and read; PATH lacking git so cmdBuilder.Capture fails to exec.","solutions":["Check the ref exists right before use: git rev-parse refs/has-been-reviewed in the package dir","Recreate the ref from current HEAD: git update-ref refs/has-been-reviewed HEAD","Re-clone the AUR package if the repository is corrupt","Verify git is installed and on PATH (git --version)"],"exampleFix":"// before\nreturn \"\", fmt.Errorf(\"%s %w\", stderr, err)\n// after\nreturn \"\", fmt.Errorf(\"resolving last-seen ref %q in %s: %s: %w\", gitDiffRefName, dir, stderr, err)","handlingStrategy":"try-catch","validationCode":"out, err := exec.Command(\"git\", \"-C\", dir, \"rev-parse\", \"--verify\", ref).Output()\nif err != nil { /* ref missing: skip diff or recreate */ }","typeGuard":"func refExists(dir, ref string) bool {\n\treturn exec.Command(\"git\", \"-C\", dir, \"rev-parse\", \"--verify\", \"--quiet\", ref).Run() == nil\n}","tryCatchPattern":"hash, err := getLastSeenHash(ctx, cb, dir)\nif err != nil {\n\tlog.Printf(\"no last-seen hash for %s: %v; showing full diff\", dir, err)\n\treturn \"\", nil // fall back to full diff\n}","preventionTips":["Use `git rev-parse --verify --quiet <ref>` as an existence check instead of a separate boolean helper","Hold the package dir stable (no re-download) while diffing","Log stderr from Capture at debug level to catch transient git failures","Serialize diff sessions to avoid concurrent ref pruning"],"tags":["git","command-execution","error-wrapping"],"backgroundTag":"git-command-failed","analyzedSha":"328f4b4939fb35f38c2f7c7ce3b8638a839bafa5","analyzedAt":"2026-09-07T16:45:12.608Z","contentChangedAt":"2026-09-07T16:45:12.608Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}