yay icon indicating copy to clipboard operation
yay copied to clipboard

fix: Correctly return exit status 1 when no packages are found

Open sarbojitrana opened this issue 1 month ago • 1 comments

Fixes #2701

Summary

This commit addresses the issue where yay -S <unknown-package> returns an exit status of 0 (Success) even though the package resolution failed. This violates standard Unix conventions for scripting and automation, as shell scripts rely on non-zero exit codes to detect failure.

Technical Rationale

The root cause was traced to the GraphFromAUR function in pkg/dep returning a nil error when all package targets failed to resolve, as it considered the search operation itself successful.

The fix implements the following changes:

  1. Error Definition: A new structured error, ErrTargetNotFound, was defined in pkg/query/errors.go to provide a specific, translatable error type for this failure mode.
  2. Failure Tracking: In pkg/dep/dep_graph.go, a counter (packagesNotFound) now tracks the number of targets that failed to be resolved in the AUR.
  3. Error Propagation: If the final count equals the total number of targets (packagesNotFound == len(targets)), GraphFromAUR now returns &query.ErrTargetNotFound{}.

This non-nil error correctly bubbles up through the execution stack to cmd/main.go, ensuring the program triggers the essential os.Exit(1) signal to the shell.

Verification Steps

The behavior was confirmed to be fixed using a local development build:

**Before Fix ** Screenshot From 2025-11-19 21-43-37

After Fix

Screenshot From 2025-11-19 21-32-14

sarbojitrana avatar Nov 19 '25 16:11 sarbojitrana

@Jguer could you please review the PR and let me know if anything needs to be changed?

sarbojitrana avatar Nov 23 '25 09:11 sarbojitrana

https://github.com/Jguer/yay/pull/2718#issuecomment-3678805344

I'm afraid this change breaks a bunch of CI users relying on yay's ignore and keep building. But since it's covering only the 100% coverage case, let's try it out.

Jguer avatar Dec 21 '25 13:12 Jguer