Skip to content

Fix TRY003: encapsulate exception messages in custom exception classes#195

Closed
Copilot wants to merge 2 commits intomainfrom
copilot/try003-fix-linter-error
Closed

Fix TRY003: encapsulate exception messages in custom exception classes#195
Copilot wants to merge 2 commits intomainfrom
copilot/try003-fix-linter-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

TRY003 flags long exception messages constructed at the raise site rather than inside the exception class. This removes the suppression and fixes all 58 violations across the codebase.

Approach

Each unique error message is moved into a dedicated exception class __init__, so call sites pass typed context instead of formatted strings:

# Before
raise ValueError(f"model_settings in task {task.name or ''} needs to be a dictionary")

# After
class TaskModelSettingsTypeError(ValueError):
    def __init__(self, task_name: str) -> None:
        super().__init__(f"model_settings in task {task_name} needs to be a dictionary")

raise TaskModelSettingsTypeError(task.name or '')

New files

  • exceptions.py — 25+ custom exception classes for the main package, organized by domain (API/token, MCP transport, runner, session, shell, template)
  • mcp_servers/codeql/exceptions.py — CodeQL-specific exceptions (NoActiveDatabaseError, LegacyServerNotSupportedError, UnsupportedOutputFormatError, etc.)

Updated files

  • available_tools.py — adds BadToolNameError/FileTypeException subclasses (InvalidToolFormatError, ToolDirNotFoundError, FiletypeMismatchError, etc.) so existing except BadToolNameError handlers are unaffected
  • All other affected modules import and use the new exception types

pyproject.toml

  • Removes TRY003 from the global ignore list
  • Adds per-file-ignores for the vendored jsonrpyc/__init__.py to preserve that third-party code unchanged

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • unsupported.example.com
    • Triggering command: /usr/bin/python python -m pytest tests/ -v (dns block)
    • Triggering command: /usr/bin/python python -m pytest tests/ -q get --global git committer.email (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix linter error TRY003 and remove from suppression list Fix TRY003: encapsulate exception messages in custom exception classes Apr 2, 2026
Copilot AI requested a review from kevinbackhouse April 2, 2026 16:21
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.

TRY003

2 participants