4848from a2a .utils .errors import (
4949 InternalError ,
5050 InvalidParamsError ,
51- ServerError ,
5251 TaskNotCancelableError ,
5352 TaskNotFoundError ,
5453 UnsupportedOperationError ,
@@ -132,7 +131,7 @@ async def on_get_task(
132131 task_id = params .id
133132 task : Task | None = await self .task_store .get (task_id , context )
134133 if not task :
135- raise ServerError ( error = TaskNotFoundError ())
134+ raise TaskNotFoundError
136135
137136 return apply_history_length (task , params )
138137
@@ -169,14 +168,12 @@ async def on_cancel_task(
169168 task_id = params .id
170169 task : Task | None = await self .task_store .get (task_id , context )
171170 if not task :
172- raise ServerError ( error = TaskNotFoundError ())
171+ raise TaskNotFoundError
173172
174173 # Check if task is in a non-cancelable state (completed, canceled, failed, rejected)
175174 if task .status .state in TERMINAL_TASK_STATES :
176- raise ServerError (
177- error = TaskNotCancelableError (
178- message = f'Task cannot be canceled - current state: { task .status .state } '
179- )
175+ raise TaskNotCancelableError (
176+ message = f'Task cannot be canceled - current state: { task .status .state } '
180177 )
181178
182179 task_manager = TaskManager (
@@ -208,17 +205,13 @@ async def on_cancel_task(
208205 consumer = EventConsumer (queue )
209206 result = await result_aggregator .consume_all (consumer )
210207 if not isinstance (result , Task ):
211- raise ServerError (
212- error = InternalError (
213- message = 'Agent did not return valid response for cancel'
214- )
208+ raise InternalError (
209+ message = 'Agent did not return valid response for cancel'
215210 )
216211
217212 if result .status .state != TaskState .TASK_STATE_CANCELED :
218- raise ServerError (
219- error = TaskNotCancelableError (
220- message = f'Task cannot be canceled - current state: { result .status .state } '
221- )
213+ raise TaskNotCancelableError (
214+ message = f'Task cannot be canceled - current state: { result .status .state } '
222215 )
223216
224217 return result
@@ -260,18 +253,14 @@ async def _setup_message_execution(
260253
261254 if task :
262255 if task .status .state in TERMINAL_TASK_STATES :
263- raise ServerError (
264- error = InvalidParamsError (
265- message = f'Task { task .id } is in terminal state: { task .status .state } '
266- )
256+ raise InvalidParamsError (
257+ message = f'Task { task .id } is in terminal state: { task .status .state } '
267258 )
268259
269260 task = task_manager .update_with_message (params .message , task )
270261 elif params .message .task_id :
271- raise ServerError (
272- error = TaskNotFoundError (
273- message = f'Task { params .message .task_id } was specified but does not exist'
274- )
262+ raise TaskNotFoundError (
263+ message = f'Task { params .message .task_id } was specified but does not exist'
275264 )
276265
277266 # Build request context
@@ -317,9 +306,7 @@ def _validate_task_id_match(self, task_id: str, event_task_id: str) -> None:
317306 event_task_id ,
318307 task_id ,
319308 )
320- raise ServerError (
321- InternalError (message = 'Task ID mismatch in agent response' )
322- )
309+ raise InternalError (message = 'Task ID mismatch in agent response' )
323310
324311 async def _send_push_notification_if_needed (
325312 self , task_id : str , event : Event
@@ -389,7 +376,7 @@ async def push_notification_callback(event: Event) -> None:
389376 await self ._cleanup_producer (producer_task , task_id )
390377
391378 if not result :
392- raise ServerError ( error = InternalError ())
379+ raise InternalError
393380
394381 if isinstance (result , Task ):
395382 self ._validate_task_id_match (task_id , result .id )
@@ -496,12 +483,12 @@ async def on_create_task_push_notification_config(
496483 Requires a `PushNotifier` to be configured.
497484 """
498485 if not self ._push_config_store :
499- raise ServerError ( error = UnsupportedOperationError ())
486+ raise UnsupportedOperationError
500487
501488 task_id = params .task_id
502489 task : Task | None = await self .task_store .get (task_id , context )
503490 if not task :
504- raise ServerError ( error = TaskNotFoundError ())
491+ raise TaskNotFoundError
505492
506493 await self ._push_config_store .set_info (
507494 task_id ,
@@ -524,13 +511,13 @@ async def on_get_task_push_notification_config(
524511 Requires a `PushConfigStore` to be configured.
525512 """
526513 if not self ._push_config_store :
527- raise ServerError ( error = UnsupportedOperationError ())
514+ raise UnsupportedOperationError
528515
529516 task_id = params .task_id
530517 config_id = params .id
531518 task : Task | None = await self .task_store .get (task_id , context )
532519 if not task :
533- raise ServerError ( error = TaskNotFoundError ())
520+ raise TaskNotFoundError
534521
535522 push_notification_configs : list [PushNotificationConfig ] = (
536523 await self ._push_config_store .get_info (
@@ -546,9 +533,7 @@ async def on_get_task_push_notification_config(
546533 push_notification_config = config ,
547534 )
548535
549- raise ServerError (
550- error = InternalError (message = 'Push notification config not found' )
551- )
536+ raise InternalError (message = 'Push notification config not found' )
552537
553538 async def on_subscribe_to_task (
554539 self ,
@@ -563,13 +548,11 @@ async def on_subscribe_to_task(
563548 task_id = params .id
564549 task : Task | None = await self .task_store .get (task_id , context )
565550 if not task :
566- raise ServerError ( error = TaskNotFoundError ())
551+ raise TaskNotFoundError
567552
568553 if task .status .state in TERMINAL_TASK_STATES :
569- raise ServerError (
570- error = UnsupportedOperationError (
571- message = f'Task { task .id } is in terminal state: { task .status .state } '
572- )
554+ raise UnsupportedOperationError (
555+ message = f'Task { task .id } is in terminal state: { task .status .state } '
573556 )
574557
575558 # The operation MUST return a Task object as the first event in the stream
@@ -588,7 +571,7 @@ async def on_subscribe_to_task(
588571
589572 queue = await self ._queue_manager .tap (task .id )
590573 if not queue :
591- raise ServerError ( error = TaskNotFoundError ())
574+ raise TaskNotFoundError
592575
593576 consumer = EventConsumer (queue )
594577 async for event in result_aggregator .consume_and_emit (consumer ):
@@ -604,12 +587,12 @@ async def on_list_task_push_notification_configs(
604587 Requires a `PushConfigStore` to be configured.
605588 """
606589 if not self ._push_config_store :
607- raise ServerError ( error = UnsupportedOperationError ())
590+ raise UnsupportedOperationError
608591
609592 task_id = params .task_id
610593 task : Task | None = await self .task_store .get (task_id , context )
611594 if not task :
612- raise ServerError ( error = TaskNotFoundError ())
595+ raise TaskNotFoundError
613596
614597 push_notification_config_list = await self ._push_config_store .get_info (
615598 task_id , context or ServerCallContext ()
@@ -635,13 +618,13 @@ async def on_delete_task_push_notification_config(
635618 Requires a `PushConfigStore` to be configured.
636619 """
637620 if not self ._push_config_store :
638- raise ServerError ( error = UnsupportedOperationError ())
621+ raise UnsupportedOperationError
639622
640623 task_id = params .task_id
641624 config_id = params .id
642625 task : Task | None = await self .task_store .get (task_id , context )
643626 if not task :
644- raise ServerError ( error = TaskNotFoundError ())
627+ raise TaskNotFoundError
645628
646629 await self ._push_config_store .delete_info (
647630 task_id , context or ServerCallContext (), config_id
0 commit comments