fix: Correctly return exit status 1 when no packages are found
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:
- Error Definition: A new structured error,
ErrTargetNotFound, was defined inpkg/query/errors.goto provide a specific, translatable error type for this failure mode. - 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. - Error Propagation: If the final count equals the total number of targets (
packagesNotFound == len(targets)),GraphFromAURnow 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 **
After Fix
@Jguer could you please review the PR and let me know if anything needs to be changed?
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.