Skip to content

📟 Operator: Fix Exit Code Lies in pebble next --json - #287

Open
matta wants to merge 1 commit into
mainfrom
operator-fix-next-json-exit-code-10000198630323544085
Open

📟 Operator: Fix Exit Code Lies in pebble next --json#287
matta wants to merge 1 commit into
mainfrom
operator-fix-next-json-exit-code-10000198630323544085

Conversation

@matta

@matta matta commented Mar 13, 2026

Copy link
Copy Markdown
Owner

😫 Friction: pebble next --json was returning exit code 0 when there were no ready tasks, unlike the human-readable pebble next format which failed with an exit code of 1. Returning success on a query that inherently failed to find an item is an "Exit Code Lie" that breaks automation scripts (like while pebble next --json; do ... done).
🤖 Fix: Modified run_next in crates/pebble/src/commands.rs to move the .is_empty() check above the if ctx.json block.
📉 Before: pebble next --json -> {"tasks":[]} (exit code: 0)
📈 After: pebble next --json -> Task 'fake' not found on stderr (exit code: 1)


PR created automatically by Jules for task 10000198630323544085 started by @matta

Moves the emptiness check for 'next' command above the JSON formatting block,
ensuring that `pebble next --json` correctly fails with an exit code of 1
and an error message on stderr instead of silently succeeding with `{"tasks":[]}`.

Added operator standard note in `.jules/operator.md` to document the convention.

Co-authored-by: matta <37314+matta@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@trunk-io

trunk-io Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an inconsistency in the pebble next --json command's exit code behavior. Previously, it would return a successful exit code (0) even when no tasks were found, which hindered scripting and automation. The changes ensure that the command now correctly signals failure with a non-zero exit code in such scenarios, improving reliability for automated workflows.

Highlights

  • Consistent Exit Codes for pebble next --json: The pebble next --json command now correctly returns a non-zero exit code (1) when no ready tasks are found, aligning its behavior with the human-readable output and preventing "Exit Code Lies" that break automation.
  • Code Logic Adjustment: The is_empty() check in run_next was moved to execute before JSON serialization, ensuring that an error is returned for empty results regardless of the output format.
  • Updated Documentation and Standards: The .jules/operator.md file was updated with a new entry detailing the standard for search/retrieval commands to return non-zero exit codes when items are not found, especially for JSON output.
  • New Integration Test: An integration test was added to cli_json.rs to specifically verify that pebble next --json fails with exit code 1 and outputs to stderr when no tasks are present, and succeeds when tasks exist.
Changelog
  • .jules/operator.md
    • Added a new section on "Exit Code Lies in Search and Retrieval Commands" to document the standard for consistent exit codes across different output formats.
  • crates/pebble/src/commands.rs
    • Moved the check for empty tasks to occur before the JSON output block, ensuring an error is returned if no tasks are found.
    • Removed the redundant empty task check after the JSON output block.
  • crates/pebble/tests/integration/cli_json.rs
    • Introduced a new test case to verify that pebble next --json returns a non-zero exit code and outputs to stderr when no tasks are available.
    • Updated an existing assertion to reflect that one task is expected after writing a task.
Activity
  • PR created automatically by Jules for task 10000198630323544085, started by @matta.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes an issue where pebble next --json would return a success exit code (0) even when no tasks were found, which is problematic for scripting. The fix involves moving the check for empty tasks before the JSON serialization logic. The associated tests have been updated to cover this new failure case, and a new entry has been added to the operator's manual.

My review includes two suggestions for improvement. First, in the integration test, I recommend strengthening the assertion to check for the specific error message on stderr, aligning with the principle of providing informative test failures. Second, in the operator's manual, I've noted that the new entry is very similar to an existing one and suggest consolidating them to avoid redundancy and improve clarity.

Comment thread .jules/operator.md
Comment on lines +11 to +14
## 2025-02-24 - Exit Code Lies in Search and Retrieval Commands
**Friction:** `pebble next --json` returned exit code 0 and an empty JSON array `{"tasks":[]}` when no tasks were found, whereas the human-readable output correctly returned a non-zero exit code.
**Insight:** Single-item search or retrieval commands (like `next` or `show`) must consistently return non-zero exit codes when the requested item is missing, regardless of the output format. Returning "null" or an empty array with exit code 0 breaks CI/CD and shell script automation that relies on exit codes for control flow.
**Standard:** Search/retrieval commands must return exit code 1 when the requested item is missing. Always check for empty results and return `Err(NotFoundError(...).into())` *before* attempting to serialize or format the output for `--json`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This new entry is very similar to the existing one on lines 7-9. While this entry is more specific to the --json flag and more accurate about the previous state, having two very similar standards about exit codes for 'not found' scenarios could be confusing.

Consider consolidating them into a single, comprehensive standard. For example, you could update the existing entry to incorporate the details about --json output, or replace both with a new, unified entry. This would improve clarity and maintainability of these operational standards.

.expect("pebble command should execute successfully");

assert!(!output.status.success());
assert!(!output.stderr.is_empty());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The assertion on stderr is a bit weak. It only checks that stderr is not empty, but it doesn't verify the error message content. This could lead to the test passing even if the command fails for an unexpected reason. It's better to assert that stderr contains the specific error message for 'no ready tasks'. This aligns with the principle of providing informative error messages in tests, similar to using expect() over unwrap().

Suggested change
assert!(!output.stderr.is_empty());
assert!(String::from_utf8_lossy(&output.stderr).contains("No ready tasks found."));
References
  1. In tests, including doctests, use expect() with a descriptive message instead of unwrap() to provide more informative error messages on failure. This principle extends to making assertions more specific to ensure tests fail informatively.

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.

1 participant