Skip to content

Conversation

@kevinmessiaen
Copy link
Member

@kevinmessiaen kevinmessiaen commented Aug 12, 2025

…g., CounterpointConfigError)


Note

Introduce dedicated exception classes and switch from ValueError to specific errors in chat, rate limiter, templates, and tools; update exports and tests accordingly.

  • Errors:
    • Add counterpoint.exceptions with CounterpointError, CounterpointConfigError, ToolError, ToolDefinitionError.
  • Core updates:
    • chat.Chat.output: raise CounterpointConfigError when output_model is missing and improve message.
    • rate_limiter.get_rate_limiter: raise CounterpointConfigError for missing id.
    • templates.render_messages_template: raise CounterpointConfigError on invalid mixed message/output.
    • tools.Tool.from_callable: raise ToolDefinitionError for missing parameter annotations.
  • Public API:
    • Export new exceptions in src/counterpoint/__init__.py.
  • Tests:
    • Update expectations to use CounterpointConfigError in tests/test_chat.py and tests/test_templates.py.

Written by Cursor Bugbot for commit c2d51fb. This will update automatically on new commits. Configure here.

@linear
Copy link

linear bot commented Aug 12, 2025

GSK-4543 [counterpoint] Introduce specific error classes (e.g., CounterpointConfigError)

Problem

Counterpoint currently relies on general-purpose exceptions (e.g., ValueError, TypeError) which makes debugging, user experience, and test coverage harder to manage.

Proposed Change

  • Create a module counterpoint.exceptions (or core/exceptions.py) with custom error types:
    • CounterpointConfigError
    • TemplateNotFoundError
  • Replace generic exceptions in core logic with these specific ones.
  • Document expected error behavior in relevant public API docstrings.

Impact

  • Improves developer feedback during debugging.
  • Enables finer-grained error handling in downstream systems like Conductor.

@kevinmessiaen kevinmessiaen changed the title Chore: [GSK-4543] [counterpoint] Introduce specific error classes (e.g., CounterpointConfigError) Chore: [GSK-4543] Introduce specific error classes (e.g., CounterpointConfigError) Aug 12, 2025
Copy link

@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 @kevinmessiaen, 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 refactors the error handling within the counterpoint library by introducing a dedicated hierarchy of custom exception classes. This change replaces generic ValueError exceptions with more specific types like CounterpointConfigError and ToolDefinitionError, enhancing error clarity, debugging, and maintainability across the codebase.

Highlights

  • New Exception Hierarchy: A new src/counterpoint/exceptions.py module has been added, defining a structured set of custom exceptions including CounterpointError as the base, and specialized subclasses like CounterpointConfigError, ToolError, and ToolDefinitionError.
  • Refactored Error Handling: Existing ValueError raises in src/counterpoint/chat.py, src/counterpoint/rate_limiter.py, src/counterpoint/templates/prompts_manager.py, and src/counterpoint/tools/tool.py have been replaced with the newly defined, more specific exception types.
  • Package-Level Exception Exposure: The src/counterpoint/init.py file has been updated to import and expose these new exception classes, making them readily accessible throughout the package.
  • Updated Unit Tests: Corresponding unit tests in tests/test_chat.py and tests/test_templates.py have been modified to assert against the new specific exception types, ensuring proper error handling validation.
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 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.

Copy link

@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 introduces specific error classes to provide more granular error handling, replacing generic ValueError exceptions. The changes are well-implemented across the application code and tests. I've provided a couple of minor suggestions to improve code style and consistency regarding import statements.

Comment on lines +3 to +8
from .exceptions import (
CounterpointConfigError,
CounterpointError,
ToolError,
ToolDefinitionError,
)

Choose a reason for hiding this comment

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

medium

For better readability and consistency, it's good practice to sort imports. In this case, sorting them logically by hierarchy would be best, with base classes appearing before their subclasses. This also makes the import order consistent with the order in __all__.

Suggested change
from .exceptions import (
CounterpointConfigError,
CounterpointError,
ToolError,
ToolDefinitionError,
)
from .exceptions import (
CounterpointError,
CounterpointConfigError,
ToolError,
ToolDefinitionError,
)


async def test_invalid_template(prompts_manager):
with pytest.raises(ValueError):
from counterpoint.exceptions import CounterpointConfigError

Choose a reason for hiding this comment

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

medium

According to PEP 8, imports should usually be at the top of the file. This local import should be moved to the top-level imports to improve code style and maintain consistency with other files in the project (e.g., tests/test_chat.py). After moving the import, this line and the following blank line can be removed.

@mattbit
Copy link
Member

mattbit commented Sep 4, 2025

sorry I had missed this, I will check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants