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
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: ");
}
}
Expand Down Expand Up @@ -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: ");
}
}
Expand All @@ -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: ");
}
}
Expand Down Expand Up @@ -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: ");
}
}
Expand Down Expand Up @@ -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: ");
}
}
Expand All @@ -259,7 +260,7 @@ public List<TaskPushNotificationConfig> 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: ");
}
}
Expand All @@ -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: ");
}
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


<properties>
<grpc.version>1.73.0</grpc.version>
<grpc.version>1.77.0</grpc.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-clean-plugin.version>3.5.0</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.14.1</maven-compiler-plugin.version>
Expand Down
31 changes: 14 additions & 17 deletions spec-grpc/src/main/java/io/a2a/grpc/A2AServiceGrpc.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
* A2AService defines the operations of the A2A protocol.
* </pre>
*/
@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 {

Expand Down Expand Up @@ -717,8 +714,8 @@ protected A2AServiceBlockingV2Stub build(
* Send a message to the agent.
* </pre>
*/
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);
}

Expand All @@ -739,8 +736,8 @@ public io.a2a.grpc.SendMessageResponse sendMessage(io.a2a.grpc.SendMessageReques
* Get the current state of a task from the agent.
* </pre>
*/
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);
}

Expand All @@ -749,8 +746,8 @@ public io.a2a.grpc.Task getTask(io.a2a.grpc.GetTaskRequest request) {
* List tasks with optional filtering and pagination.
* </pre>
*/
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);
}

Expand All @@ -759,8 +756,8 @@ public io.a2a.grpc.ListTasksResponse listTasks(io.a2a.grpc.ListTasksRequest requ
* Cancel a task.
* </pre>
*/
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);
}

Expand Down Expand Up @@ -792,8 +789,8 @@ public io.a2a.grpc.TaskPushNotificationConfig setTaskPushNotificationConfig(io.a
* Get a push notification config for a task.
* </pre>
*/
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);
}

Expand All @@ -802,8 +799,8 @@ public io.a2a.grpc.TaskPushNotificationConfig getTaskPushNotificationConfig(io.a
* Get a list of push notifications configured for a task.
* </pre>
*/
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);
}

Expand All @@ -822,8 +819,8 @@ public io.a2a.grpc.AgentCard getExtendedAgentCard(io.a2a.grpc.GetExtendedAgentCa
* Delete a push notification config for a task.
* </pre>
*/
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);
}
}
Expand Down