Skip to content

🚀 feat: Handle schema decoder panics#24

Merged
ReneWerner87 merged 1 commit intomainfrom
handle_decoder_panics
May 21, 2025
Merged

🚀 feat: Handle schema decoder panics#24
ReneWerner87 merged 1 commit intomainfrom
handle_decoder_panics

Conversation

@ReneWerner87
Copy link
Copy Markdown
Member

@ReneWerner87 ReneWerner87 commented May 21, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling during decoding to prevent application crashes by converting panics into error messages.
  • Tests

    • Added a test to verify that panics during decoding are properly caught and returned as errors.
  • Chores

    • Updated the .gitignore file to exclude JetBrains IDE configuration files.

@ReneWerner87 ReneWerner87 added this to v3 May 21, 2025
@ReneWerner87 ReneWerner87 requested a review from a team as a code owner May 21, 2025 12:33
@ReneWerner87 ReneWerner87 requested review from efectn, gaby and sixcolors and removed request for a team May 21, 2025 12:33
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented May 21, 2025

Walkthrough

The .gitignore file was updated to exclude the .idea directory. In the decoder, the Decode method now recovers from panics and returns them as errors, with adjustments to error handling logic. A new test ensures that panics during decoding are properly caught and returned as errors.

Changes

File(s) Change Summary
.gitignore Added .idea to ignore JetBrains IDE project files.
decoder.go Updated Decode to recover from panics, renamed local error variable, and improved error handling and return logic.
decoder_test.go Added test to verify panics during decoding are caught and returned as errors.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Decoder

    Caller->>Decoder: Decode(dst, src, files...)
    activate Decoder
    Decoder->>Decoder: defer recover from panic
    Decoder->>Decoder: Perform decoding logic
    alt Panic occurs
        Decoder->>Decoder: recover and convert panic to error
    end
    Decoder-->>Caller: Return error (if any)
Loading

Poem

In the warren of code, a panic once grew,
But now it's caught, as all wise bunnies do!
With .idea ignored and errors in hand,
Our tests now ensure the decoder will stand.
So hop along, coder, your code is robust—
No more runtime surprises, in bunnies we trust! 🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch handle_decoder_panics
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@gaby gaby requested a review from Copilot May 21, 2025 12:34
@codecov
Copy link
Copy Markdown

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.

Project coverage is 88.31%. Comparing base (d1d1d97) to head (b7fe30a).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
decoder.go 75.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
- Coverage   88.55%   88.31%   -0.24%     
==========================================
  Files           4        4              
  Lines         926      933       +7     
==========================================
+ Hits          820      824       +4     
- Misses         90       91       +1     
- Partials       16       18       +2     
Flag Coverage Δ
unittests 88.31% <75.00%> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@gaby gaby changed the title 🚀 Handle schema decoder panics 🚀 feat: Handle schema decoder panics May 21, 2025
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🔭 Outside diff range comments (1)
decoder.go (1)

83-89: ⚠️ Potential issue

Shadowing of the named return err makes panic-recovery brittle

By naming the return value (err error) you intend to mutate it from the defer block.
Inside Decode, however, several short-var declarations (:=) re-declare a new err, shadowing the named one.
The most prominent is:

if parts, err := d.cache.parsePath(...); err == nil { ... }

Any assignment to that inner err does not touch the named variable the defer relies on.
The result is confusing scoping and increases the chance of losing the recovered error.

Suggestion: introduce a distinct identifier for the inner scopes, e.g.:

if parts, perr := d.cache.parsePath(...); perr == nil { ... }

or keep using multiErr and avoid re-using err altogether.

🧹 Nitpick comments (1)
.gitignore (1)

4-4: Consider adding editor-specific folders only once per toolchain

Ignoring .idea is perfectly fine, but you may want to put all editor/IDE artefacts ( .vscode/, .DS_Store, etc.) together in a dedicated section to keep the file organised and avoid future duplication.
(Not a blocker – just a housekeeping tip.)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1d1d97 and b7fe30a.

📒 Files selected for processing (3)
  • .gitignore (1 hunks)
  • decoder.go (2 hunks)
  • decoder_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
decoder_test.go (1)
decoder.go (1)
  • NewDecoder (21-23)
🪛 GitHub Check: codecov/patch
decoder.go

[warning] 105-105: decoder.go#L105
Added line #L105 was not covered by tests


[warning] 119-119: decoder.go#L119
Added line #L119 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: unit (1.22.x, windows-latest)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, windows-latest)

Copy link
Copy Markdown
Member

@gaby gaby left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@ReneWerner87 ReneWerner87 merged commit 452f46c into main May 21, 2025
17 of 18 checks passed
@ReneWerner87 ReneWerner87 deleted the handle_decoder_panics branch May 21, 2025 14:59
@github-project-automation github-project-automation bot moved this to Done in v3 May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants