-
Notifications
You must be signed in to change notification settings - Fork 426
Expand file tree
/
Copy patherrors.py
More file actions
145 lines (93 loc) · 3.93 KB
/
errors.py
File metadata and controls
145 lines (93 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""Custom exceptions and error types for A2A server-side errors.
This module contains A2A-specific error codes,
as well as server exception classes.
"""
class A2AError(Exception):
"""Base exception for A2A errors."""
message: str = 'A2A Error'
def __init__(self, message: str | None = None):
if message:
self.message = message
super().__init__(self.message)
class TaskNotFoundError(A2AError):
"""Exception raised when a task is not found."""
message = 'Task not found'
class TaskNotCancelableError(A2AError):
"""Exception raised when a task cannot be canceled."""
message = 'Task cannot be canceled'
class PushNotificationNotSupportedError(A2AError):
"""Exception raised when push notifications are not supported."""
message = 'Push Notification is not supported'
class UnsupportedOperationError(A2AError):
"""Exception raised when an operation is not supported."""
message = 'This operation is not supported'
class ContentTypeNotSupportedError(A2AError):
"""Exception raised when the content type is incompatible."""
message = 'Incompatible content types'
class InternalError(A2AError):
"""Exception raised for internal server errors."""
message = 'Internal error'
class InvalidAgentResponseError(A2AError):
"""Exception raised when the agent response is invalid."""
message = 'Invalid agent response'
class AuthenticatedExtendedCardNotConfiguredError(A2AError):
"""Exception raised when the authenticated extended card is not configured."""
message = 'Authenticated Extended Card is not configured'
class InvalidParamsError(A2AError):
"""Exception raised when parameters are invalid."""
message = 'Invalid params'
class InvalidRequestError(A2AError):
"""Exception raised when the request is invalid."""
message = 'Invalid Request'
class MethodNotFoundError(A2AError):
"""Exception raised when a method is not found."""
message = 'Method not found'
class ExtensionSupportRequiredError(A2AError):
"""Exception raised when extension support is required but not present."""
message = 'Extension support required'
class VersionNotSupportedError(A2AError):
"""Exception raised when the requested version is not supported."""
message = 'Version not supported'
# For backward compatibility if needed, or just aliases for clean refactor
# We remove the Pydantic models here.
__all__ = [
'A2A_ERROR_REASONS',
'A2A_REASON_TO_ERROR',
'JSON_RPC_ERROR_CODE_MAP',
'ExtensionSupportRequiredError',
'InternalError',
'InvalidAgentResponseError',
'InvalidParamsError',
'InvalidRequestError',
'MethodNotFoundError',
'PushNotificationNotSupportedError',
'TaskNotCancelableError',
'TaskNotFoundError',
'UnsupportedOperationError',
'VersionNotSupportedError',
]
JSON_RPC_ERROR_CODE_MAP: dict[type[A2AError], int] = {
TaskNotFoundError: -32001,
TaskNotCancelableError: -32002,
PushNotificationNotSupportedError: -32003,
UnsupportedOperationError: -32004,
ContentTypeNotSupportedError: -32005,
InvalidAgentResponseError: -32006,
AuthenticatedExtendedCardNotConfiguredError: -32007,
InvalidParamsError: -32602,
InvalidRequestError: -32600,
MethodNotFoundError: -32601,
InternalError: -32603,
}
A2A_ERROR_REASONS = {
TaskNotFoundError: 'TASK_NOT_FOUND',
TaskNotCancelableError: 'TASK_NOT_CANCELABLE',
PushNotificationNotSupportedError: 'PUSH_NOTIFICATION_NOT_SUPPORTED',
UnsupportedOperationError: 'UNSUPPORTED_OPERATION',
ContentTypeNotSupportedError: 'CONTENT_TYPE_NOT_SUPPORTED',
InvalidAgentResponseError: 'INVALID_AGENT_RESPONSE',
AuthenticatedExtendedCardNotConfiguredError: 'EXTENDED_AGENT_CARD_NOT_CONFIGURED',
ExtensionSupportRequiredError: 'EXTENSION_SUPPORT_REQUIRED',
VersionNotSupportedError: 'VERSION_NOT_SUPPORTED',
}
A2A_REASON_TO_ERROR = {reason: cls for cls, reason in A2A_ERROR_REASONS.items()}