Skip to content

Handle google.rpc.ErrorInfo in HttpJson*Stub class #2237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JoeWang1127 opened this issue Nov 10, 2023 · 6 comments
Open

Handle google.rpc.ErrorInfo in HttpJson*Stub class #2237

JoeWang1127 opened this issue Nov 10, 2023 · 6 comments
Assignees
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@JoeWang1127
Copy link
Collaborator

Followup on #2229.

The generated HttpJsonEchoStub can't handle message type: google.rpc.ErrorInfo introduced by echo.proto (version 0.29.0).
A easy integration test:

@Test
public void testEchoErrorDetails() {
  EchoErrorDetailsResponse response = httpjsonClient.echoErrorDetails(
      EchoErrorDetailsRequest
          .newBuilder()
          .setSingleDetailText("singleDetailText1774380934")
          .addAllMultiDetailText(new ArrayList<>())
          .build());
  assertThat(response.hasSingleDetail()).isEqualTo(true);
}

failed with the following error message:

Caused by: com.google.protobuf.InvalidProtocolBufferException: Cannot resolve type: type.googleapis.com/google.rpc.ErrorInfo
    at com.google.protobuf.util.JsonFormat$ParserImpl.mergeAny(JsonFormat.java:1511)

Possible solution:
Add the message type in

for (Method method : service.methods()) {
if (method.hasLro()) {
TypeNode anyType = method.lro().responseType();
anyTypes.put(anyType.reference().fullName(), anyType);
anyType = method.lro().metadataType();
anyTypes.put(anyType.reference().fullName(), anyType);
}
}

@JoeWang1127 JoeWang1127 added the priority: p2 Moderately-important priority. Fix may not be included in next release. label Nov 10, 2023
@ddixit14 ddixit14 added the type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. label Nov 13, 2023
@JoeWang1127
Copy link
Collaborator Author

In the possible solution part, the types are added recursively in TypeRegistry.Builder.add() method.

However, only two types serves as the "root" of this method, WaitRequest and WaitResponse, we need to understand the reason behind this before adding ErrorInfo into the registry.

@lqiu96
Copy link
Contributor

lqiu96 commented Nov 13, 2023

Took a look at some of the code in Gax and I believe it may be due to the ProtoOperationTransformers:

public PackedT apply(Any input) {
try {
return input == null || packedClass == null ? null : input.unpack(packedClass);
} catch (InvalidProtocolBufferException | ClassCastException e) {
throw new IllegalStateException(
"Failed to unpack object from 'any' field. Expected "
+ packedClass.getName()
+ ", found "
+ input.getTypeUrl());
}
}

ServiceStubSettings transforms it from Any to the classes:

.setResponseTransformer(
ProtoOperationTransformers.ResponseTransformer.create(WaitResponse.class))
.setMetadataTransformer(
ProtoOperationTransformers.MetadataTransformer.create(WaitMetadata.class))

I believe conversion from Any -> Class would require a TypeRegistry.

@zhumin8 zhumin8 self-assigned this Nov 20, 2023
@blakeli0
Copy link
Collaborator

I'm afraid this issue is more complicated than we expected. The new Showcase feature tests that we can deserialize an Any field to a concrete field in ErrorInfo, which is only used by the Error Details feature, and it was deferred last year. See b/260671246 for details. In short, we can not support this test for HttpJson stubs until Error Details feature is implemented for REGAPIC.

In the mean time, I think it's still worth it to add a showcase test for gRPC.

@diegomarquezp
Copy link
Contributor

diegomarquezp commented Feb 7, 2024

we can not support this test for HttpJson stubs until Error Details feature is implemented for REGAPIC

I'll be demoting this to p3

@diegomarquezp diegomarquezp added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Feb 7, 2024
@blakeli0
Copy link
Collaborator

blakeli0 commented Aug 9, 2024

Verified that adding ErrorInfo to the type registry should fix this issue, see #3093. However, we need to figure out where exact to add the additional types, either in Gax or generated layers.

Theoretically this issue can be tackled individually, but it will likely be resolved if the actionable ErrorDetails project is implemented for httpjson. Hence keeping this as a P3.

@baeminbo
Copy link

I reported a related issue at googleapis/java-spanner#3640. That issue is about a failure in parsing error status during server streaming calls. It has two underlying problems:

  1. HttpJsonClientCallImpl.consumeMessageFromStream() uses the TypeRegistry from HttpJsonCallOptions, ignoring the default registry in ProtoMessageResponseParser. If the TypeRegistry is null in HttpJsonCallOptions, a NullPointerException is thrown.
  2. DebugInfo is not added in TypeRegistry for HttpJson*Stub (this issue discussed here). This causes InvalidProtocolBufferException with "Cannot resolve type: type.googleapis.com/google.rpc.DebugInfo" even if the NPE issue is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

7 participants