Skip to content

🧹 chore: Handle errIndexTooLarge during decode#28

Merged
ReneWerner87 merged 1 commit intomainfrom
codex/2025-06-18-01-54-49
Jun 18, 2025
Merged

🧹 chore: Handle errIndexTooLarge during decode#28
ReneWerner87 merged 1 commit intomainfrom
codex/2025-06-18-01-54-49

Conversation

@gaby
Copy link
Copy Markdown
Member

@gaby gaby commented Jun 18, 2025

Summary

  • handle errIndexTooLarge as a decode error rather than an unknown key
  • update test for the new behavior when an index exceeds the parser limit

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messages when input data exceeds allowed index size, providing more specific feedback to users.
  • Tests

    • Updated tests to verify the new error handling behavior for index size limits.

@gaby gaby requested a review from a team as a code owner June 18, 2025 01:54
@gaby gaby requested review from ReneWerner87, efectn and sixcolors and removed request for a team June 18, 2025 01:54
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 18, 2025

Walkthrough

The changes update error handling in the Decoder.Decode method to distinguish between index-too-large errors and unknown key errors, adding specific handling for the errIndexTooLarge case. Corresponding test expectations are updated to reflect this new error handling logic.

Changes

File(s) Change Summary
decoder.go Refined error handling in Decode: now adds errIndexTooLarge to errors when appropriate, otherwise adds UnknownKeyError based on ignoreUnknownKeys.
decoder_test.go Updated test to expect errIndexTooLarge in error list when index exceeds parser limit, instead of UnknownKeyError.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Decoder
    participant Cache

    Client->>Decoder: Decode(input)
    Decoder->>Cache: parsePath(input)
    alt parsePath returns errIndexTooLarge
        Decoder->>Decoder: Add errIndexTooLarge to multiErrors
    else parsePath returns other error
        alt ignoreUnknownKeys is false
            Decoder->>Decoder: Add UnknownKeyError to multiErrors
        end
    end
    Decoder-->>Client: Return result or multiErrors
Loading

Possibly related PRs

Suggested labels

🧹 Updates

Suggested reviewers

  • sixcolors

Poem

In Decoder’s warren, errors leap and bound,
Now index limits are clearly found.
No more confusion with unknown keys,
Each error’s caught with rabbit’s ease.
Tests now hop in step anew—
Precise as paws on morning dew!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch codex/2025-06-18-01-54-49

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.

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @gaby, 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 improves the precision of error reporting within the decoder by distinguishing errIndexTooLarge from generic unknown key errors. This ensures that specific parsing failures related to out-of-bounds indices are correctly identified and propagated, and the corresponding test case has been updated to reflect this new behavior.

Highlights

  • Refined Error Handling: I've updated the Decode method in decoder.go to specifically recognize and handle errIndexTooLarge. Previously, if a path parsing error occurred and ignoreUnknownKeys was false, it would default to an UnknownKeyError. Now, if the underlying error is errIndexTooLarge, that specific error is recorded, providing more precise error reporting.
  • Test Case Alignment: The test TestDecodeIndexExceedsParserLimit in decoder_test.go has been updated. It now correctly asserts that errIndexTooLarge is returned when an index exceeds the parser's limit, aligning with the refined error handling logic in the decoder.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.46%. Comparing base (ffa6b91) to head (e27a898).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
+ Coverage   88.42%   88.46%   +0.03%     
==========================================
  Files           4        4              
  Lines         942      945       +3     
==========================================
+ Hits          833      836       +3     
  Misses         91       91              
  Partials       18       18              
Flag Coverage Δ
unittests 88.46% <100.00%> (+0.03%) ⬆️

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

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

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 enhances error handling by distinguishing errIndexTooLarge from a generic UnknownKeyError, providing more specific feedback. The logic in decoder.go is sound, and the test in decoder_test.go has been updated appropriately.

@gaby gaby changed the title Return errIndexTooLarge when parsing paths 🧹 chore: Handle errIndexTooLarge during decode Jun 18, 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: 0

🧹 Nitpick comments (2)
decoder.go (1)

126-131: Explicitly surfacing errIndexTooLarge is sensible – tiny nit on clarity

The additional branch correctly prevents an oversize-index error from being hidden by the ignore unknown keys setting.
Consider a micro-refactor to make intent clearer and avoid the double negative:

} else {
    switch {
    case errors.Is(err, errIndexTooLarge):
        multiErrors[path] = err                // propagate as-is
    case !d.ignoreUnknownKeys:
        multiErrors[path] = UnknownKeyError{Key: path}
    }
}

Same behaviour, slightly flatter.
No functional blockers – change looks good.

decoder_test.go (1)

3170-3173: Guard against wrapped sentinel errors

reflect.DeepEqual relies on pointer equality for the error interface.
If cache.parsePath ever starts wrapping (fmt.Errorf("%w", errIndexTooLarge)), this assertion will fail even though errors.Is would pass.

A future-proof tweak:

-expected := MultiError{"n1.1001.value": errIndexTooLarge}
+expected := MultiError{"n1.1001.value": errIndexTooLarge}
+if !errors.Is(err.(MultiError)["n1.1001.value"], errIndexTooLarge) {
+    t.Fatalf("expected errIndexTooLarge, got %v", err)
+}

Not required for current behaviour but avoids brittle equality.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ffa6b91 and e27a898.

📒 Files selected for processing (2)
  • decoder.go (1 hunks)
  • decoder_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: unit (1.22.x, ubuntu-latest)
  • GitHub Check: Compare
  • GitHub Check: unit (1.23.x, ubuntu-latest)
  • GitHub Check: unit (1.24.x, macos-13)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, macos-latest)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: unit (1.24.x, macos-latest)
  • GitHub Check: unit (1.22.x, windows-latest)
  • GitHub Check: unit (1.24.x, ubuntu-latest)
  • GitHub Check: unit (1.22.x, macos-13)
  • GitHub Check: unit (1.22.x, macos-latest)
  • GitHub Check: repeated

@ReneWerner87 ReneWerner87 merged commit 03290a2 into main Jun 18, 2025
18 checks passed
@ReneWerner87 ReneWerner87 deleted the codex/2025-06-18-01-54-49 branch June 18, 2025 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants