Skip to content

Commit 042e004

Browse files
committed
update grpc-java version; handle StatusException error
1 parent fcc02ec commit 042e004

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcErrorMapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
import io.a2a.spec.TaskNotFoundError;
1414
import io.a2a.spec.UnsupportedOperationError;
1515
import io.grpc.Status;
16-
import io.grpc.StatusRuntimeException;
1716

1817
/**
1918
* Utility class to map gRPC StatusRuntimeException to appropriate A2A error types
2019
*/
2120
public class GrpcErrorMapper {
2221

23-
public static A2AClientException mapGrpcError(StatusRuntimeException e) {
22+
public static A2AClientException mapGrpcError(Throwable e) {
2423
return mapGrpcError(e, "gRPC error: ");
2524
}
2625

27-
public static A2AClientException mapGrpcError(StatusRuntimeException e, String errorPrefix) {
28-
Status.Code code = e.getStatus().getCode();
29-
String description = e.getStatus().getDescription();
26+
public static A2AClientException mapGrpcError(Throwable e, String errorPrefix) {
27+
Status status = Status.fromThrowable(e);
28+
Status.Code code = status.getCode();
29+
String description = status.getDescription();
3030

3131
// Extract the actual error type from the description if possible
3232
// (using description because the same code can map to multiple errors -

client/transport/grpc/src/main/java/io/a2a/client/transport/grpc/GrpcTransport.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import io.a2a.spec.TaskResubscriptionRequest;
4949
import io.grpc.Channel;
5050
import io.grpc.Metadata;
51+
import io.grpc.StatusException;
5152
import io.grpc.StatusRuntimeException;
5253
import io.grpc.stub.MetadataUtils;
5354
import io.grpc.stub.StreamObserver;
@@ -97,7 +98,7 @@ public EventKind sendMessage(MessageSendParams request, @Nullable ClientCallCont
9798
} else {
9899
throw new A2AClientException("Server response did not contain a message or task");
99100
}
100-
} catch (StatusRuntimeException e) {
101+
} catch (StatusRuntimeException | StatusException e) {
101102
throw GrpcErrorMapper.mapGrpcError(e, "Failed to send message: ");
102103
}
103104
}
@@ -134,7 +135,7 @@ public Task getTask(TaskQueryParams request, @Nullable ClientCallContext context
134135
try {
135136
A2AServiceBlockingV2Stub stubWithMetadata = createBlockingStubWithMetadata(context, payloadAndHeaders);
136137
return FromProto.task(stubWithMetadata.getTask(getTaskRequest));
137-
} catch (StatusRuntimeException e) {
138+
} catch (StatusRuntimeException | StatusException e) {
138139
throw GrpcErrorMapper.mapGrpcError(e, "Failed to get task: ");
139140
}
140141
}
@@ -152,7 +153,7 @@ public Task cancelTask(TaskIdParams request, @Nullable ClientCallContext context
152153
try {
153154
A2AServiceBlockingV2Stub stubWithMetadata = createBlockingStubWithMetadata(context, payloadAndHeaders);
154155
return FromProto.task(stubWithMetadata.cancelTask(cancelTaskRequest));
155-
} catch (StatusRuntimeException e) {
156+
} catch (StatusRuntimeException | StatusException e) {
156157
throw GrpcErrorMapper.mapGrpcError(e, "Failed to cancel task: ");
157158
}
158159
}
@@ -197,7 +198,7 @@ public ListTasksResult listTasks(ListTasksParams request, @Nullable ClientCallCo
197198
grpcResponse.getTasksCount(),
198199
grpcResponse.getNextPageToken().isEmpty() ? null : grpcResponse.getNextPageToken()
199200
);
200-
} catch (StatusRuntimeException e) {
201+
} catch (StatusRuntimeException | StatusException e) {
201202
throw GrpcErrorMapper.mapGrpcError(e, "Failed to list tasks: ");
202203
}
203204
}
@@ -219,7 +220,7 @@ public TaskPushNotificationConfig setTaskPushNotificationConfiguration(TaskPushN
219220
try {
220221
A2AServiceBlockingV2Stub stubWithMetadata = createBlockingStubWithMetadata(context, payloadAndHeaders);
221222
return FromProto.taskPushNotificationConfig(stubWithMetadata.createTaskPushNotificationConfig(grpcRequest));
222-
} catch (StatusRuntimeException e) {
223+
} catch (StatusRuntimeException | StatusException e) {
223224
throw GrpcErrorMapper.mapGrpcError(e, "Failed to create task push notification config: ");
224225
}
225226
}
@@ -239,7 +240,7 @@ public TaskPushNotificationConfig getTaskPushNotificationConfiguration(
239240
try {
240241
A2AServiceBlockingV2Stub stubWithMetadata = createBlockingStubWithMetadata(context, payloadAndHeaders);
241242
return FromProto.taskPushNotificationConfig(stubWithMetadata.getTaskPushNotificationConfig(grpcRequest));
242-
} catch (StatusRuntimeException e) {
243+
} catch (StatusRuntimeException | StatusException e) {
243244
throw GrpcErrorMapper.mapGrpcError(e, "Failed to get task push notification config: ");
244245
}
245246
}
@@ -261,7 +262,7 @@ public List<TaskPushNotificationConfig> listTaskPushNotificationConfigurations(
261262
return stubWithMetadata.listTaskPushNotificationConfig(grpcRequest).getConfigsList().stream()
262263
.map(FromProto::taskPushNotificationConfig)
263264
.collect(Collectors.toList());
264-
} catch (StatusRuntimeException e) {
265+
} catch (StatusRuntimeException | StatusException e) {
265266
throw GrpcErrorMapper.mapGrpcError(e, "Failed to list task push notification config: ");
266267
}
267268
}
@@ -280,7 +281,7 @@ public void deleteTaskPushNotificationConfigurations(DeleteTaskPushNotificationC
280281
try {
281282
A2AServiceBlockingV2Stub stubWithMetadata = createBlockingStubWithMetadata(context, payloadAndHeaders);
282283
stubWithMetadata.deleteTaskPushNotificationConfig(grpcRequest);
283-
} catch (StatusRuntimeException e) {
284+
} catch (StatusRuntimeException | StatusException e) {
284285
throw GrpcErrorMapper.mapGrpcError(e, "Failed to delete task push notification config: ");
285286
}
286287
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939

4040
<properties>
41-
<grpc.version>1.73.0</grpc.version>
41+
<grpc.version>1.77.0</grpc.version>
4242
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4343
<maven-clean-plugin.version>3.5.0</maven-clean-plugin.version>
4444
<maven-compiler-plugin.version>3.14.1</maven-compiler-plugin.version>

spec-grpc/src/main/java/io/a2a/grpc/A2AServiceGrpc.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
* - AgentCard is a static resource with only a get method.
1717
* </pre>
1818
*/
19-
@javax.annotation.Generated(
20-
value = "by gRPC proto compiler (version 1.73.0)",
21-
comments = "Source: a2a.proto")
2219
@io.grpc.stub.annotations.GrpcGenerated
2320
public final class A2AServiceGrpc {
2421

@@ -773,8 +770,8 @@ protected A2AServiceBlockingV2Stub build(
773770
* task once it is completed, or a LRO if requested.
774771
* </pre>
775772
*/
776-
public io.a2a.grpc.SendMessageResponse sendMessage(io.a2a.grpc.SendMessageRequest request) {
777-
return io.grpc.stub.ClientCalls.blockingUnaryCall(
773+
public io.a2a.grpc.SendMessageResponse sendMessage(io.a2a.grpc.SendMessageRequest request) throws io.grpc.StatusException {
774+
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
778775
getChannel(), getSendMessageMethod(), getCallOptions(), request);
779776
}
780777

@@ -796,8 +793,8 @@ public io.a2a.grpc.SendMessageResponse sendMessage(io.a2a.grpc.SendMessageReques
796793
* Get the current state of a task from the agent.
797794
* </pre>
798795
*/
799-
public io.a2a.grpc.Task getTask(io.a2a.grpc.GetTaskRequest request) {
800-
return io.grpc.stub.ClientCalls.blockingUnaryCall(
796+
public io.a2a.grpc.Task getTask(io.a2a.grpc.GetTaskRequest request) throws io.grpc.StatusException {
797+
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
801798
getChannel(), getGetTaskMethod(), getCallOptions(), request);
802799
}
803800

@@ -806,8 +803,8 @@ public io.a2a.grpc.Task getTask(io.a2a.grpc.GetTaskRequest request) {
806803
* List tasks with optional filtering and pagination.
807804
* </pre>
808805
*/
809-
public io.a2a.grpc.ListTasksResponse listTasks(io.a2a.grpc.ListTasksRequest request) {
810-
return io.grpc.stub.ClientCalls.blockingUnaryCall(
806+
public io.a2a.grpc.ListTasksResponse listTasks(io.a2a.grpc.ListTasksRequest request) throws io.grpc.StatusException {
807+
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
811808
getChannel(), getListTasksMethod(), getCallOptions(), request);
812809
}
813810

@@ -817,8 +814,8 @@ public io.a2a.grpc.ListTasksResponse listTasks(io.a2a.grpc.ListTasksRequest requ
817814
* more task updates for the task.
818815
* </pre>
819816
*/
820-
public io.a2a.grpc.Task cancelTask(io.a2a.grpc.CancelTaskRequest request) {
821-
return io.grpc.stub.ClientCalls.blockingUnaryCall(
817+
public io.a2a.grpc.Task cancelTask(io.a2a.grpc.CancelTaskRequest request) throws io.grpc.StatusException {
818+
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
822819
getChannel(), getCancelTaskMethod(), getCallOptions(), request);
823820
}
824821

@@ -842,8 +839,8 @@ public io.a2a.grpc.Task cancelTask(io.a2a.grpc.CancelTaskRequest request) {
842839
* Set a push notification config for a task.
843840
* </pre>
844841
*/
845-
public io.a2a.grpc.TaskPushNotificationConfig createTaskPushNotificationConfig(io.a2a.grpc.CreateTaskPushNotificationConfigRequest request) {
846-
return io.grpc.stub.ClientCalls.blockingUnaryCall(
842+
public io.a2a.grpc.TaskPushNotificationConfig createTaskPushNotificationConfig(io.a2a.grpc.CreateTaskPushNotificationConfigRequest request) throws io.grpc.StatusException {
843+
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
847844
getChannel(), getCreateTaskPushNotificationConfigMethod(), getCallOptions(), request);
848845
}
849846

@@ -852,8 +849,8 @@ public io.a2a.grpc.TaskPushNotificationConfig createTaskPushNotificationConfig(i
852849
* Get a push notification config for a task.
853850
* </pre>
854851
*/
855-
public io.a2a.grpc.TaskPushNotificationConfig getTaskPushNotificationConfig(io.a2a.grpc.GetTaskPushNotificationConfigRequest request) {
856-
return io.grpc.stub.ClientCalls.blockingUnaryCall(
852+
public io.a2a.grpc.TaskPushNotificationConfig getTaskPushNotificationConfig(io.a2a.grpc.GetTaskPushNotificationConfigRequest request) throws io.grpc.StatusException {
853+
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
857854
getChannel(), getGetTaskPushNotificationConfigMethod(), getCallOptions(), request);
858855
}
859856

@@ -862,8 +859,8 @@ public io.a2a.grpc.TaskPushNotificationConfig getTaskPushNotificationConfig(io.a
862859
* Get a list of push notifications configured for a task.
863860
* </pre>
864861
*/
865-
public io.a2a.grpc.ListTaskPushNotificationConfigResponse listTaskPushNotificationConfig(io.a2a.grpc.ListTaskPushNotificationConfigRequest request) {
866-
return io.grpc.stub.ClientCalls.blockingUnaryCall(
862+
public io.a2a.grpc.ListTaskPushNotificationConfigResponse listTaskPushNotificationConfig(io.a2a.grpc.ListTaskPushNotificationConfigRequest request) throws io.grpc.StatusException {
863+
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
867864
getChannel(), getListTaskPushNotificationConfigMethod(), getCallOptions(), request);
868865
}
869866

@@ -872,8 +869,8 @@ public io.a2a.grpc.ListTaskPushNotificationConfigResponse listTaskPushNotificati
872869
* GetAgentCard returns the agent card for the agent.
873870
* </pre>
874871
*/
875-
public io.a2a.grpc.AgentCard getAgentCard(io.a2a.grpc.GetAgentCardRequest request) {
876-
return io.grpc.stub.ClientCalls.blockingUnaryCall(
872+
public io.a2a.grpc.AgentCard getAgentCard(io.a2a.grpc.GetAgentCardRequest request) throws io.grpc.StatusException {
873+
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
877874
getChannel(), getGetAgentCardMethod(), getCallOptions(), request);
878875
}
879876

@@ -882,8 +879,8 @@ public io.a2a.grpc.AgentCard getAgentCard(io.a2a.grpc.GetAgentCardRequest reques
882879
* Delete a push notification config for a task.
883880
* </pre>
884881
*/
885-
public com.google.protobuf.Empty deleteTaskPushNotificationConfig(io.a2a.grpc.DeleteTaskPushNotificationConfigRequest request) {
886-
return io.grpc.stub.ClientCalls.blockingUnaryCall(
882+
public com.google.protobuf.Empty deleteTaskPushNotificationConfig(io.a2a.grpc.DeleteTaskPushNotificationConfigRequest request) throws io.grpc.StatusException {
883+
return io.grpc.stub.ClientCalls.blockingV2UnaryCall(
887884
getChannel(), getDeleteTaskPushNotificationConfigMethod(), getCallOptions(), request);
888885
}
889886
}

0 commit comments

Comments
 (0)