Skip to content

Improve error handling #508

Open
anaslimem wants to merge 1 commit into
feyninc:mainfrom
anaslimem:improve_error_handling
Open

Improve error handling #508
anaslimem wants to merge 1 commit into
feyninc:mainfrom
anaslimem:improve_error_handling

Conversation

@anaslimem

Copy link
Copy Markdown
Contributor

PR: Improve Error Handling in CodeChunker

Summary

This pull request improves error handling in the CodeChunker class by replacing an assert statement with a proper RuntimeError exception. This change ensures that library users receive clear, actionable error messages when the parser fails to initialize, rather than an ambiguous AssertionError.

Details

  • File: src/chonkie/chunker/code.py
  • Change:
    • Replaced:
      assert self.parser is not None, "Parser is not initialized."
      with:
      if self.parser is None:
          raise RuntimeError("Parser failed to initialize. Language detection or initialization failed.")
  • Reason:
    • Assertions are intended for internal logic errors and can be disabled with Python's -O flag.
    • Raising a specific exception provides clearer feedback to developers using the library and allows for better error handling downstream.

Impact

  • Improves developer experience for all users of the CodeChunker class.
  • No breaking changes to the public API.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @anaslimem, 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 refines the error handling mechanism within the CodeChunker class by transitioning from an assertion-based check to a more robust exception-based approach. This change ensures that any issues with parser initialization are communicated explicitly through a RuntimeError, providing developers with precise feedback and improving the overall reliability and usability of the library without altering its public API.

Highlights

  • Improved Error Handling: Replaced an assert statement with a RuntimeError exception for parser initialization failures in the CodeChunker class.
  • Enhanced Developer Experience: Library users will now receive clearer, actionable error messages when the parser fails to initialize, facilitating better error handling downstream.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/chonkie/chunker/code.py
    • Replaced an assert statement with a RuntimeError for uninitialized parsers.
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

The pull request effectively improves error handling by replacing an assert statement with a RuntimeError exception. This change is beneficial as it provides clearer and more robust error feedback to users, aligning with best practices for library development where assertions are typically reserved for internal logic checks that should never fail in production. The change is well-justified and implemented correctly.

@chonk-lain

Copy link
Copy Markdown
Member

@anaslimem
I have updated CodeChunker entirely in v1.6.6 so this is no longer valid.
also thanks for bringing this to my attention, but raise and if...raise is almost the same, i am most of the time using either of them to silence some ty errors since types of [something| None] does make CI red : ')
would invite you to close this whole line's reason at the time of creation is to make the linter happy.
TY for you understanding : )

@chonk-lain chonk-lain added the wontfix This will not be worked on label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants