Skip to content

🛡️ Sentinel: [MEDIUM] Replace panic with graceful Result propagation - #290

Open
matta wants to merge 1 commit into
mainfrom
sentinel/replace-panic-with-graceful-error-propagation-2202468366419687362
Open

🛡️ Sentinel: [MEDIUM] Replace panic with graceful Result propagation#290
matta wants to merge 1 commit into
mainfrom
sentinel/replace-panic-with-graceful-error-propagation-2202468366419687362

Conversation

@matta

@matta matta commented Mar 14, 2026

Copy link
Copy Markdown
Owner

🚨 Severity: MEDIUM
💡 Vulnerability: The use of unwrap_or_else(|| panic!(...)) inside internal graph mutation functions (apply_reverse_blocks, apply_reverse_update) could cause an abrupt termination (Denial of Service) of the CLI tool if a validated ID somehow goes missing from the graph due to a bug or concurrent modification.
🎯 Impact: Abrupt program termination via panic! inside core application logic handles errors poorly, leading to a degraded user experience or abrupt crashing of automated workflows.
🔧 Fix: Replaced instances of unwrap_or_else(|| panic!(...)) with ok_or_else(|| eyre!(...))? in functions that return color_eyre::eyre::Result, allowing errors to propagate safely back up to the caller where they can be properly formatted and presented to the user.
✅ Verification: Ran cargo fmt, just check, and just test to verify the codebase compiles and all tests pass with the new error propagation in place. Additionally logged the learning to .jules/sentinel.md.


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

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 14, 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 enhances the robustness of the CLI tool by refactoring critical error handling within core application logic. It addresses a potential Denial of Service scenario where missing graph IDs could cause the program to crash, ensuring that such issues now result in graceful error propagation rather than abrupt termination. This improves user experience and the reliability of automated workflows.

Highlights

  • Graceful Error Handling: Replaced instances of unwrap_or_else(|| panic!(...)) with ok_or_else(|| eyre!(...))? in internal graph mutation functions (apply_reverse_blocks, apply_reverse_update) to prevent abrupt program termination and allow for safe error propagation.
Changelog
  • .jules/sentinel.md
    • Added a new entry detailing the vulnerability, learning, and prevention related to replacing panic! with Result propagation.
  • crates/pebble/src/commands_add.rs
    • Modified the apply_reverse_blocks function to propagate errors using ok_or_else instead of panic! when a validated task ID is not found.
  • crates/pebble/src/commands_write.rs
    • Updated the apply_reverse_update function in two locations to use ok_or_else for error propagation instead of panic! when a validated task ID is missing.
Activity
  • The codebase was verified by running cargo fmt, just check, and just test to ensure compilation and test pass.
  • A new learning entry was added to .jules/sentinel.md documenting the change and its rationale.
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 replaces panic! calls with Result propagation in graph mutation functions to provide more graceful error handling and avoid abrupt CLI termination. The implementation correctly uses ok_or_else to convert Options to Results. However, this approach deviates from a repository-wide general rule that recommends using panic! for invariant violations to clearly signal a logic bug. I've added a comment to discuss this potential shift in error handling strategy.

.get(&target_id)
.cloned()
.unwrap_or_else(|| panic!("BUG: validated task ID should exist in graph"));
.ok_or_else(|| eyre!("BUG: validated task ID should exist in graph"))?;

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 change replaces a panic! with Result propagation, which improves the user experience by avoiding an abrupt crash. However, it contradicts a general rule stating that invariant violations like this (a validated ID missing after validation) should trigger a panic! to signal a logic bug.

This new approach treats a bug as a reportable error rather than a program-terminating event. If this is the intended new error handling strategy for the CLI, consider updating the general rule to maintain consistency across the project.

References
  1. When a value is expected to exist due to a prior validation (i.e., an invariant), use .expect() or panic! to signal a logic bug if the value is not found. Returning a user-facing error in this case would incorrectly mask a bug as a user error.

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