feat: implement snapshot-integrated custom LRO error parsing (POC 3) - #14080
feat: implement snapshot-integrated custom LRO error parsing (POC 3)#14080nnicolee wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for propagating custom Long-Running Operation (LRO) error details across both gRPC and HTTP/JSON transports. It adds the HttpJsonLroErrorParser interface, implements a ComputeLroErrorParser for Google Cloud Compute, and updates OperationSnapshot and ProtoOperationTransformers to carry ErrorDetails. However, the package matching logic in HttpJsonServiceStubClassComposer incorrectly targets com.google.cloud.compute.v1small as well, which will cause compilation failures in the generated golden files because ComputeLroErrorParser is package-private and unavailable in that package. This should be resolved by explicitly excluding v1small from the generator's condition.
| .apply("setError", Arrays.asList(getHttpErrorStatusCodeExpr, getHttpErrorMessageExpr)) | ||
| .apply(newBuilderExpr); | ||
|
|
||
| if (service.pakkage().startsWith("com.google.cloud.compute.v1")) { |
There was a problem hiding this comment.
The package check service.pakkage().startsWith("com.google.cloud.compute.v1") evaluates to true for "com.google.cloud.compute.v1small". This causes the generator to incorrectly inject .setErrorParser(new ComputeLroErrorParser()) into the v1small golden files (as seen in HttpJsonAddressesStub.java and HttpJsonRegionOperationsStub.java).
Since ComputeLroErrorParser is a hand-written class in com.google.cloud.compute.v1.stub and is package-private, it is not present or accessible in com.google.cloud.compute.v1small.stub, which will cause compilation failures when building the goldens.
To fix this and properly ignore the v1small package as intended, we should explicitly exclude it in the condition.
| if (service.pakkage().startsWith("com.google.cloud.compute.v1")) { | |
| if (service.pakkage().startsWith("com.google.cloud.compute.v1") | |
| && !service.pakkage().startsWith("com.google.cloud.compute.v1small")) { |
|
|
006e4a7 to
6c6aed1
Compare


Overview
This PR implements POC 3 for custom LRO error details propagation. In this design, we encapsulate the custom error parsing concern directly inside
HttpJsonOperationSnapshotduring its instantiation lifecycle.This approach keeps
ProtoOperationTransformerscompletely clean and aligned with the gRPC implementation, avoiding the need for multiple overloads or passing custom error parser objects down to the response transformer.Changes
1. GAX Core (
gax-httpjson)HttpJsonOperationSnapshot.java: Added.setErrorParser(HttpJsonLroErrorParser)toHttpJsonOperationSnapshot.Builder. If configured,build()invokes the parser on the response object to populateerrorDetailsanderrorMessageon the built snapshot instance.ProtoOperationTransformers.java: Reverted theResponseTransformerto a single clean implementation. It no longer acceptsHttpJsonLroErrorParserand instead directly readsoperationSnapshot.getErrorDetails()andoperationSnapshot.getErrorMessage().2. Generator (
gapic-generator-java)HttpJsonServiceStubClassComposer.java: Conditionally generates.setErrorParser(new ComputeLroErrorParser())on theHttpJsonOperationSnapshotbuilder for long-running compute APIs (ignoring thev1smallintegration test package to maintain golden safety).RetrySettingsComposer.java: Reverted the POC 2 changes that registered the error parser inside theResponseTransformersettings factory.Verification
bazelisk test //sdk-platform-java/test/integration:compute-> PASSEDmvn test -pl :gapic-generator-java-> PASSED