Skip to content

fix(cli): exit successfully on zero query results#28

Open
oritwoen wants to merge 1 commit intomainfrom
fix/query-zero-results-exit-code
Open

fix(cli): exit successfully on zero query results#28
oritwoen wants to merge 1 commit intomainfrom
fix/query-zero-results-exit-code

Conversation

@oritwoen
Copy link
Owner

shaha query was using bail!() when no results matched, which makes the process exit with code 1. Zero results is a valid query outcome, not an error - it breaks scripts that use exit codes to distinguish "query worked, nothing found" from "something actually went wrong" (bad hex input, missing database, I/O failure).

Replaced the bail with a stderr message and Ok(()).

Closes #19

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

Warning

Rate limit exceeded

@oritwoen has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: b2d7314b-ff3c-4363-ac79-6acd3c585e75

📥 Commits

Reviewing files that changed from the base of the PR and between 73af24e and 87f89b5.

📒 Files selected for processing (1)
  • src/cli/query.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/query-zero-results-exit-code
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/query-zero-results-exit-code
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Confidence score: 3/5

  • There is a concrete user-facing behavior gap in src/cli/query.rs: a successful no-match path returns early and skips JSON output, so --format json can emit empty stdout instead of valid [].
  • Given the severity (6/10) and high confidence (9/10), this creates real regression risk for automation/scripts that parse stdout as JSON, so this is more than a minor housekeeping issue.
  • Pay close attention to src/cli/query.rs - ensure the no-match success path still writes [] for JSON format before returning.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/cli/query.rs">

<violation number="1" location="src/cli/query.rs:57">
P2: This early return skips JSON output on a successful no-match query. `shaha query ... --format json` should still print `[]`, otherwise scripts reading stdout as JSON get empty input instead of a valid result.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

if results.is_empty() {
bail!("No matches found");
crate::status!("No matches found");
return Ok(());
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This early return skips JSON output on a successful no-match query. shaha query ... --format json should still print [], otherwise scripts reading stdout as JSON get empty input instead of a valid result.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/cli/query.rs, line 57:

<comment>This early return skips JSON output on a successful no-match query. `shaha query ... --format json` should still print `[]`, otherwise scripts reading stdout as JSON get empty input instead of a valid result.</comment>

<file context>
@@ -53,7 +53,8 @@ pub fn run(args: QueryArgs) -> Result<()> {
     if results.is_empty() {
-        bail!("No matches found");
+        crate::status!("No matches found");
+        return Ok(());
     }
 
</file context>
Fix with Cubic

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.

query exits with error on zero results

1 participant