diff --git a/client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcErrorMapper.java b/client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcErrorMapper.java index 5f0db8f0f..cf245553b 100644 --- a/client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcErrorMapper.java +++ b/client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcErrorMapper.java @@ -13,20 +13,20 @@ import io.a2a.spec.TaskNotFoundError; import io.a2a.spec.UnsupportedOperationError; import io.grpc.Status; -import io.grpc.StatusRuntimeException; /** - * Utility class to map gRPC StatusRuntimeException to appropriate A2A error types + * Utility class to map gRPC exceptions to appropriate A2A error types */ public class GrpcErrorMapper { - public static A2AClientException mapGrpcError(StatusRuntimeException e) { + public static A2AClientException mapGrpcError(Throwable e) { return mapGrpcError(e, "gRPC error: "); } - public static A2AClientException mapGrpcError(StatusRuntimeException e, String errorPrefix) { - Status.Code code = e.getStatus().getCode(); - String description = e.getStatus().getDescription(); + public static A2AClientException mapGrpcError(Throwable e, String errorPrefix) { + Status status = Status.fromThrowable(e); + Status.Code code = status.getCode(); + String description = status.getDescription(); // Extract the actual error type from the description if possible // (using description because the same code can map to multiple errors - diff --git a/client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcTransport.java b/client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcTransport.java index 1f6dc19a4..4ff3c0bc8 100644 --- a/client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcTransport.java +++ b/client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcTransport.java @@ -44,6 +44,7 @@ import io.a2a.spec.TaskQueryParams; import io.grpc.Channel; import io.grpc.Metadata; +import io.grpc.StatusException; import io.grpc.StatusRuntimeException; import io.grpc.stub.MetadataUtils; import io.grpc.stub.StreamObserver; @@ -93,7 +94,7 @@ public EventKind sendMessage(MessageSendParams request, @Nullable ClientCallCont } else { throw new A2AClientException("Server response did not contain a message or task"); } - } catch (StatusRuntimeException e) { + } catch (StatusRuntimeException | StatusException e) { throw GrpcErrorMapper.mapGrpcError(e, "Failed to send message: "); } } @@ -130,7 +131,7 @@ public Task getTask(TaskQueryParams request, @Nullable ClientCallContext context try { A2AServiceBlockingV2Stub stubWithMetadata = createBlockingStubWithMetadata(context, payloadAndHeaders); return FromProto.task(stubWithMetadata.getTask(getTaskRequest)); - } catch (StatusRuntimeException e) { + } catch (StatusRuntimeException | StatusException e) { throw GrpcErrorMapper.mapGrpcError(e, "Failed to get task: "); } } @@ -148,7 +149,7 @@ public Task cancelTask(TaskIdParams request, @Nullable ClientCallContext context try { A2AServiceBlockingV2Stub stubWithMetadata = createBlockingStubWithMetadata(context, payloadAndHeaders); return FromProto.task(stubWithMetadata.cancelTask(cancelTaskRequest)); - } catch (StatusRuntimeException e) { + } catch (StatusRuntimeException | StatusException e) { throw GrpcErrorMapper.mapGrpcError(e, "Failed to cancel task: "); } } @@ -195,7 +196,7 @@ public ListTasksResult listTasks(ListTasksParams request, @Nullable ClientCallCo grpcResponse.getTasksCount(), grpcResponse.getNextPageToken().isEmpty() ? null : grpcResponse.getNextPageToken() ); - } catch (StatusRuntimeException e) { + } catch (StatusRuntimeException | StatusException e) { throw GrpcErrorMapper.mapGrpcError(e, "Failed to list tasks: "); } } @@ -237,7 +238,7 @@ public TaskPushNotificationConfig getTaskPushNotificationConfiguration( try { A2AServiceBlockingV2Stub stubWithMetadata = createBlockingStubWithMetadata(context, payloadAndHeaders); return FromProto.taskPushNotificationConfig(stubWithMetadata.getTaskPushNotificationConfig(grpcRequest)); - } catch (StatusRuntimeException e) { + } catch (StatusRuntimeException | StatusException e) { throw GrpcErrorMapper.mapGrpcError(e, "Failed to get task push notification config: "); } } @@ -259,7 +260,7 @@ public List listTaskPushNotificationConfigurations( return stubWithMetadata.listTaskPushNotificationConfig(grpcRequest).getConfigsList().stream() .map(FromProto::taskPushNotificationConfig) .collect(Collectors.toList()); - } catch (StatusRuntimeException e) { + } catch (StatusRuntimeException | StatusException e) { throw GrpcErrorMapper.mapGrpcError(e, "Failed to list task push notification config: "); } } @@ -278,7 +279,7 @@ public void deleteTaskPushNotificationConfigurations(DeleteTaskPushNotificationC try { A2AServiceBlockingV2Stub stubWithMetadata = createBlockingStubWithMetadata(context, payloadAndHeaders); stubWithMetadata.deleteTaskPushNotificationConfig(grpcRequest); - } catch (StatusRuntimeException e) { + } catch (StatusRuntimeException | StatusException e) { throw GrpcErrorMapper.mapGrpcError(e, "Failed to delete task push notification config: "); } } diff --git a/pom.xml b/pom.xml index e4bc77a17..854bf3f73 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ - 1.73.0 + 1.77.0 UTF-8 3.5.0 3.14.1 diff --git a/spec-grpc/src/main/java/io/a2a/grpc/A2AServiceGrpc.java b/spec-grpc/src/main/java/io/a2a/grpc/A2AServiceGrpc.java index a20922afe..d5261ab39 100644 --- a/spec-grpc/src/main/java/io/a2a/grpc/A2AServiceGrpc.java +++ b/spec-grpc/src/main/java/io/a2a/grpc/A2AServiceGrpc.java @@ -7,9 +7,6 @@ * A2AService defines the operations of the A2A protocol. * */ -@javax.annotation.Generated( - value = "by gRPC proto compiler (version 1.73.0)", - comments = "Source: a2a.proto") @io.grpc.stub.annotations.GrpcGenerated public final class A2AServiceGrpc { @@ -717,8 +714,8 @@ protected A2AServiceBlockingV2Stub build( * Send a message to the agent. * */ - public io.a2a.grpc.SendMessageResponse sendMessage(io.a2a.grpc.SendMessageRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( + public io.a2a.grpc.SendMessageResponse sendMessage(io.a2a.grpc.SendMessageRequest request) throws io.grpc.StatusException { + return io.grpc.stub.ClientCalls.blockingV2UnaryCall( getChannel(), getSendMessageMethod(), getCallOptions(), request); } @@ -739,8 +736,8 @@ public io.a2a.grpc.SendMessageResponse sendMessage(io.a2a.grpc.SendMessageReques * Get the current state of a task from the agent. * */ - public io.a2a.grpc.Task getTask(io.a2a.grpc.GetTaskRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( + public io.a2a.grpc.Task getTask(io.a2a.grpc.GetTaskRequest request) throws io.grpc.StatusException { + return io.grpc.stub.ClientCalls.blockingV2UnaryCall( getChannel(), getGetTaskMethod(), getCallOptions(), request); } @@ -749,8 +746,8 @@ public io.a2a.grpc.Task getTask(io.a2a.grpc.GetTaskRequest request) { * List tasks with optional filtering and pagination. * */ - public io.a2a.grpc.ListTasksResponse listTasks(io.a2a.grpc.ListTasksRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( + public io.a2a.grpc.ListTasksResponse listTasks(io.a2a.grpc.ListTasksRequest request) throws io.grpc.StatusException { + return io.grpc.stub.ClientCalls.blockingV2UnaryCall( getChannel(), getListTasksMethod(), getCallOptions(), request); } @@ -759,8 +756,8 @@ public io.a2a.grpc.ListTasksResponse listTasks(io.a2a.grpc.ListTasksRequest requ * Cancel a task. * */ - public io.a2a.grpc.Task cancelTask(io.a2a.grpc.CancelTaskRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( + public io.a2a.grpc.Task cancelTask(io.a2a.grpc.CancelTaskRequest request) throws io.grpc.StatusException { + return io.grpc.stub.ClientCalls.blockingV2UnaryCall( getChannel(), getCancelTaskMethod(), getCallOptions(), request); } @@ -792,8 +789,8 @@ public io.a2a.grpc.TaskPushNotificationConfig setTaskPushNotificationConfig(io.a * Get a push notification config for a task. * */ - public io.a2a.grpc.TaskPushNotificationConfig getTaskPushNotificationConfig(io.a2a.grpc.GetTaskPushNotificationConfigRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( + public io.a2a.grpc.TaskPushNotificationConfig getTaskPushNotificationConfig(io.a2a.grpc.GetTaskPushNotificationConfigRequest request) throws io.grpc.StatusException { + return io.grpc.stub.ClientCalls.blockingV2UnaryCall( getChannel(), getGetTaskPushNotificationConfigMethod(), getCallOptions(), request); } @@ -802,8 +799,8 @@ public io.a2a.grpc.TaskPushNotificationConfig getTaskPushNotificationConfig(io.a * Get a list of push notifications configured for a task. * */ - public io.a2a.grpc.ListTaskPushNotificationConfigResponse listTaskPushNotificationConfig(io.a2a.grpc.ListTaskPushNotificationConfigRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( + public io.a2a.grpc.ListTaskPushNotificationConfigResponse listTaskPushNotificationConfig(io.a2a.grpc.ListTaskPushNotificationConfigRequest request) throws io.grpc.StatusException { + return io.grpc.stub.ClientCalls.blockingV2UnaryCall( getChannel(), getListTaskPushNotificationConfigMethod(), getCallOptions(), request); } @@ -822,8 +819,8 @@ public io.a2a.grpc.AgentCard getExtendedAgentCard(io.a2a.grpc.GetExtendedAgentCa * Delete a push notification config for a task. * */ - public com.google.protobuf.Empty deleteTaskPushNotificationConfig(io.a2a.grpc.DeleteTaskPushNotificationConfigRequest request) { - return io.grpc.stub.ClientCalls.blockingUnaryCall( + public com.google.protobuf.Empty deleteTaskPushNotificationConfig(io.a2a.grpc.DeleteTaskPushNotificationConfigRequest request) throws io.grpc.StatusException { + return io.grpc.stub.ClientCalls.blockingV2UnaryCall( getChannel(), getDeleteTaskPushNotificationConfigMethod(), getCallOptions(), request); } }