be9b60c8a9
Address code review findings: - Wrap AG-UI tool call dispatch in try/except with compensating TOOL_CALL_END to prevent clients hanging on partial emission - Reject non-dict/non-str args at the dispatch layer (lists, ints, None) - Guard against None event value before calling .get() - Fix docstring examples that reuse variable names (won't compile) - Introduce CopilotKitError base class; all exceptions now inherit from it; CopilotKitMisuseError inherits from both CopilotKitError and ValueError - Add missing validation tests for name and args across LangGraph and CrewAI Python variants, plus AG-UI dispatch edge cases Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""Exceptions for CopilotKit."""
|
|
|
|
|
|
class CopilotKitError(Exception):
|
|
"""Base exception for all CopilotKit errors.
|
|
|
|
Catch this to handle any CopilotKit-specific exception.
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class ActionNotFoundException(CopilotKitError):
|
|
"""Exception raised when an action or agent is not found."""
|
|
|
|
def __init__(self, name: str):
|
|
self.name = name
|
|
super().__init__(f"Action '{name}' not found.")
|
|
|
|
|
|
class AgentNotFoundException(CopilotKitError):
|
|
"""Exception raised when an agent is not found."""
|
|
|
|
def __init__(self, name: str):
|
|
self.name = name
|
|
super().__init__(f"Agent '{name}' not found.")
|
|
|
|
|
|
class ActionExecutionException(CopilotKitError):
|
|
"""Exception raised when an action fails to execute."""
|
|
|
|
def __init__(self, name: str, error: Exception):
|
|
self.name = name
|
|
self.error = error
|
|
super().__init__(f"Action '{name}' failed to execute: {error}")
|
|
|
|
|
|
class AgentExecutionException(CopilotKitError):
|
|
"""Exception raised when an agent fails to execute."""
|
|
|
|
def __init__(self, name: str, error: Exception):
|
|
self.name = name
|
|
self.error = error
|
|
super().__init__(f"Agent '{name}' failed to execute: {error}")
|
|
|
|
|
|
class CopilotKitMisuseError(CopilotKitError, ValueError):
|
|
"""Exception raised when CopilotKit detects incorrect usage of its APIs.
|
|
|
|
Inherits from both CopilotKitError (for ``except CopilotKitError``) and
|
|
ValueError (for backward compatibility with ``except ValueError`` handlers).
|
|
"""
|
|
|
|
pass
|