Description
When a Compute Engine long-running operation completes with status: DONE and an operation-level error, the Java client exception produced by OperationFuture.get() appears to keep only httpErrorStatusCode / httpErrorMessage in the exception message. Structured details under operation.error.errors[] are not included, which can discard the actionable provider error.
Example operation payload shape:
status: DONE
error.errors[0].code: INVALID_USAGE
error.errors[0].message: No attached disk found with device name '<deviceName>'
httpErrorStatusCode: 400
httpErrorMessage: BAD REQUEST
The thrown exception message becomes similar to:
com.google.api.gax.rpc.InvalidArgumentException: Operation with name "..." failed with status = HttpJsonStatusCode{statusCode=INVALID_ARGUMENT} and message = BAD REQUEST
The important detail INVALID_USAGE: No attached disk found with device name ... is not present in the exception message.
Why this matters
For Compute operations such as InstancesClient.detachDiskAsync(...).get(), BAD REQUEST / INVALID_ARGUMENT is too generic for operators and applications to distinguish idempotent conditions from real invalid input. The structured operation error contains the actionable reason, but it is not surfaced by the default exception path.
Code path observed
Current generated Compute client code seems to build the REST LRO snapshot from only the HTTP error status/message:
InstancesClient.detachDiskAsync(...) calls detachDiskOperationCallable().futureCall(request):
|
public final OperationFuture<Operation, Operation> detachDiskAsync( |
|
String project, String zone, String instance, String deviceName) { |
|
DetachDiskInstanceRequest request = |
|
DetachDiskInstanceRequest.newBuilder() |
|
.setProject(project) |
|
.setZone(zone) |
|
.setInstance(instance) |
|
.setDeviceName(deviceName) |
|
.build(); |
|
return detachDiskAsync(request); |
|
} |
|
|
|
// AUTO-GENERATED DOCUMENTATION AND METHOD. |
|
/** |
|
* Detaches a disk from an instance. |
|
* |
|
* <p>Sample code: |
|
* |
|
* <pre>{@code |
|
* // This snippet has been automatically generated and should be regarded as a code template only. |
|
* // It will require modifications to work: |
|
* // - It may require correct/in-range values for request initialization. |
|
* // - It may require specifying regional endpoints when creating the service client as shown in |
|
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library |
|
* try (InstancesClient instancesClient = InstancesClient.create()) { |
|
* DetachDiskInstanceRequest request = |
|
* DetachDiskInstanceRequest.newBuilder() |
|
* .setDeviceName("deviceName780988929") |
|
* .setInstance("instance555127957") |
|
* .setProject("project-309310695") |
|
* .setRequestId("requestId693933066") |
|
* .setZone("zone3744684") |
|
* .build(); |
|
* Operation response = instancesClient.detachDiskAsync(request).get(); |
|
* } |
|
* }</pre> |
|
* |
|
* @param request The request object containing all of the parameters for the API call. |
|
* @throws com.google.api.gax.rpc.ApiException if the remote call fails |
|
*/ |
|
public final OperationFuture<Operation, Operation> detachDiskAsync( |
|
DetachDiskInstanceRequest request) { |
|
return detachDiskOperationCallable().futureCall(request); |
HttpJsonInstancesStub detach disk operation snapshot uses only response.getHttpErrorStatusCode() and response.getHttpErrorMessage():
|
.setOperationSnapshotFactory( |
|
(DetachDiskInstanceRequest request, Operation response) -> { |
|
StringBuilder opName = new StringBuilder(response.getName()); |
|
opName.append(":").append(request.getProject()); |
|
opName.append(":").append(request.getZone()); |
|
return HttpJsonOperationSnapshot.newBuilder() |
|
.setName(opName.toString()) |
|
.setMetadata(response) |
|
.setDone(Status.DONE.equals(response.getStatus())) |
|
.setResponse(response) |
|
.setError(response.getHttpErrorStatusCode(), response.getHttpErrorMessage()) |
|
.build(); |
InstancesStubSettings wires this into ProtoOperationTransformers.ResponseTransformer.create(Operation.class):
|
builder |
|
.detachDiskOperationSettings() |
|
.setInitialCallSettings( |
|
UnaryCallSettings |
|
.<DetachDiskInstanceRequest, OperationSnapshot>newUnaryCallSettingsBuilder() |
|
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes")) |
|
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params")) |
|
.build()) |
|
.setResponseTransformer( |
|
ProtoOperationTransformers.ResponseTransformer.create(Operation.class)) |
|
.setMetadataTransformer( |
|
ProtoOperationTransformers.MetadataTransformer.create(Operation.class)) |
In gax, the response transformer creates the exception message from operationSnapshot.getErrorCode() and operationSnapshot.getErrorMessage() only:
HTTP 400 is then mapped to INVALID_ARGUMENT, and ApiExceptionFactory maps that to InvalidArgumentException:
Expected behavior
When the operation response contains structured error details, the thrown exception should expose or preserve them. For example, the exception message or an accessible error detail field should include something like:
INVALID_USAGE: No attached disk found with device name '<deviceName>'
Actual behavior
The default exception message only includes:
status = HttpJsonStatusCode{statusCode=INVALID_ARGUMENT} and message = BAD REQUEST
Possible fixes
- Include
Operation.error.errors[] in the generated Compute OperationSnapshot error message, where available.
- Or preserve the original Compute
Operation error details in the gax exception / ErrorDetails so callers can inspect them programmatically.
- Or provide documented guidance for retrieving the full failed operation response after
OperationFuture.get() throws.
If this belongs in googleapis/sdk-platform-java instead of this generated client repo, please redirect or transfer. The generated Compute client appears to be where the Compute-specific Operation.error.errors[] data is first collapsed into generic HTTP status/message.
Description
When a Compute Engine long-running operation completes with
status: DONEand an operation-level error, the Java client exception produced byOperationFuture.get()appears to keep onlyhttpErrorStatusCode/httpErrorMessagein the exception message. Structured details underoperation.error.errors[]are not included, which can discard the actionable provider error.Example operation payload shape:
The thrown exception message becomes similar to:
The important detail
INVALID_USAGE: No attached disk found with device name ...is not present in the exception message.Why this matters
For Compute operations such as
InstancesClient.detachDiskAsync(...).get(),BAD REQUEST/INVALID_ARGUMENTis too generic for operators and applications to distinguish idempotent conditions from real invalid input. The structured operation error contains the actionable reason, but it is not surfaced by the default exception path.Code path observed
Current generated Compute client code seems to build the REST LRO snapshot from only the HTTP error status/message:
InstancesClient.detachDiskAsync(...)callsdetachDiskOperationCallable().futureCall(request):google-cloud-java/java-compute/google-cloud-compute/src/main/java/com/google/cloud/compute/v1/InstancesClient.java
Lines 2489 to 2531 in 58e50fc
HttpJsonInstancesStubdetach disk operation snapshot uses onlyresponse.getHttpErrorStatusCode()andresponse.getHttpErrorMessage():google-cloud-java/java-compute/google-cloud-compute/src/main/java/com/google/cloud/compute/v1/stub/HttpJsonInstancesStub.java
Lines 671 to 682 in 58e50fc
InstancesStubSettingswires this intoProtoOperationTransformers.ResponseTransformer.create(Operation.class):google-cloud-java/java-compute/google-cloud-compute/src/main/java/com/google/cloud/compute/v1/stub/InstancesStubSettings.java
Lines 2294 to 2305 in 58e50fc
In gax, the response transformer creates the exception message from
operationSnapshot.getErrorCode()andoperationSnapshot.getErrorMessage()only:HTTP 400 is then mapped to
INVALID_ARGUMENT, andApiExceptionFactorymaps that toInvalidArgumentException:Expected behavior
When the operation response contains structured error details, the thrown exception should expose or preserve them. For example, the exception message or an accessible error detail field should include something like:
Actual behavior
The default exception message only includes:
Possible fixes
Operation.error.errors[]in the generated ComputeOperationSnapshoterror message, where available.Operationerror details in the gax exception /ErrorDetailsso callers can inspect them programmatically.OperationFuture.get()throws.If this belongs in
googleapis/sdk-platform-javainstead of this generated client repo, please redirect or transfer. The generated Compute client appears to be where the Compute-specificOperation.error.errors[]data is first collapsed into generic HTTP status/message.