Skip to content

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

Merged
Jguer merged 3 commits into
Jguer:nextfrom
sarbojitrana:fix/issue-2701-exit-status
Dec 21, 2025
Merged

fix: Correctly return exit status 1 when no packages are found#2705
Jguer merged 3 commits into
Jguer:nextfrom
sarbojitrana:fix/issue-2701-exit-status

Conversation

@sarbojitrana

Copy link
Copy Markdown
Contributor

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
sarbojitrana requested a review from Jguer as a code owner November 19, 2025 16:20
@sarbojitrana

Copy link
Copy Markdown
Contributor Author

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

@Jguer

Jguer commented Dec 21, 2025

Copy link
Copy Markdown
Owner

#2718 (comment)

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
Jguer merged commit c466b96 into Jguer:next Dec 21, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Status code returned is zero even though package does not exist

2 participants