Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ignore = [
"TRY003",
"G004",
"TRY201",
"FIX002",
]

select = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ async def on_message_send(
consumer, blocking=blocking
)
if not result:
raise ServerError(error=InternalError())
raise ServerError(error=InternalError()) # noqa: TRY301
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.

medium

While adding noqa: TRY301 silences the linter, it's worth considering the underlying reason for the warning. The tryceratops linter flags raising exceptions that are direct subclasses of Exception, encouraging more specific exception hierarchies.

The project already defines A2AServerError which seems intended as a base for application-specific exceptions. However, ServerError inherits directly from Exception.

For better maintainability and a clearer exception hierarchy, consider refactoring ServerError to inherit from A2AServerError in src/a2a/utils/errors.py. This would make ServerError part of a custom exception tree, which is better practice and might allow removing these noqa comments in the future.

As an example, the change in src/a2a/utils/errors.py would look like this:

class ServerError(A2AServerError):
    # ...

This change is outside the scope of this PR, but it would be a valuable future improvement.


if isinstance(result, Task):
self._validate_task_id_match(task_id, result.id)
Expand Down
4 changes: 2 additions & 2 deletions src/a2a/server/request_handlers/jsonrpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async def on_cancel_task(
CancelTaskSuccessResponse,
CancelTaskResponse,
)
raise ServerError(error=TaskNotFoundError())
raise ServerError(error=TaskNotFoundError()) # noqa: TRY301
except ServerError as e:
return CancelTaskResponse(
root=JSONRPCErrorResponse(
Expand Down Expand Up @@ -339,7 +339,7 @@ async def on_get_task(
GetTaskSuccessResponse,
GetTaskResponse,
)
raise ServerError(error=TaskNotFoundError())
raise ServerError(error=TaskNotFoundError()) # noqa: TRY301
except ServerError as e:
return GetTaskResponse(
root=JSONRPCErrorResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ async def get_info(self, task_id: str) -> list[PushNotificationConfig]:
for model in models:
try:
configs.append(self._from_orm(model))
except ValueError:
except ValueError: # noqa: PERF203
logger.exception(
'Could not deserialize push notification config for task %s, config %s',
model.task_id,
Expand Down
Loading