Skip to content

test(showcase): Add gRPC and HttpJson Showcase ITs to verify Error Details - #13928

Open
nnicolee wants to merge 4 commits into
mainfrom
test/showcase-errordetails
Open

test(showcase): Add gRPC and HttpJson Showcase ITs to verify Error Details#13928
nnicolee wants to merge 4 commits into
mainfrom
test/showcase-errordetails

Conversation

@nnicolee

Copy link
Copy Markdown
Contributor

Description

This PR introduces E2E integration test coverage for standard and custom error details using the FailEchoWithDetails RPC in Showcase, validating the exception propagation and deserialization pipeline across both gRPC and HTTP/JSON transports.

Key Changes

  • gRPC Transport Verification:
    • Verifies unpacking and correctness of all 10 standard error details (e.g. ErrorInfo, RetryInfo, DebugInfo, QuotaFailure, PreconditionFailure, BadRequest, RequestInfo, ResourceInfo, Help, LocalizedMessage).
    • Verifies that Showcase-specific custom trailers (e.g. PoetryError) are successfully unpacked and mapped into the client-side ErrorDetails.
    • Verifies dynamic message propagation inside custom trailers when parameters are passed to the request.
  • HTTP/JSON Transport Verification:
    • Verifies that error status code mapping (e.g. ABORTED) propagates correctly.
    • Handles GAX's HTTP/JSON parser boundaries when dealing with unregistered custom types (like PoetryError) in JSON status payloads.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new integration test class, ITErrorDetails.java, to verify that standard and custom error details are correctly parsed and unpacked from ApiException for both gRPC and HTTP/JSON clients. The review feedback highlights two main areas for improvement: ensuring exception-safe resource cleanup in destroyClients() to prevent potential resource leaks if one of the clients fails to close, and avoiding the use of fully qualified class names when there are no naming conflicts to improve code readability.

Comment on lines +56 to +63
static void destroyClients() throws InterruptedException {
grpcClient.close();
httpjsonClient.close();

grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS);
httpjsonClient.awaitTermination(
TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If grpcClient.close() throws an exception, httpjsonClient.close() will not be called, leading to a potential resource leak. To ensure both clients are closed and terminated properly, use nested try-finally blocks.

  static void destroyClients() throws InterruptedException {
    try {
      try {
        grpcClient.close();
      } finally {
        grpcClient.awaitTermination(TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS);
      }
    } finally {
      try {
        httpjsonClient.close();
      } finally {
        httpjsonClient.awaitTermination(
            TestClientInitializer.AWAIT_TERMINATION_SECONDS, TimeUnit.SECONDS);
      }
    }
  }
References
  1. When managing a collection of closeable resources (e.g., scopes), ensure they are closed in the reverse order of their creation (LIFO). The implementation must be exception-safe to prevent resource leaks, meaning all opened resources should be closed even if exceptions occur during their creation or closing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other existing integration tests uses this sequential pattern (such as ITIam.java, ITPagination.java, ITServerSideStreaming.java, etc.), we can leave this as-is to maintain consistency and readability.

@nnicolee
nnicolee marked this pull request as ready for review July 28, 2026 18:40
@nnicolee
nnicolee requested review from a team as code owners July 28, 2026 18:40
@nnicolee
nnicolee requested a review from lqiu96 July 28, 2026 18:40
@nnicolee
nnicolee force-pushed the test/showcase-errordetails branch from f2ca894 to dbe16db Compare July 28, 2026 20:53
Comment on lines +135 to +137
// Verify mismatched type returns null safely (mismatch unpacking)
EchoResponse mismatchedDetail = errorDetails.getMessage(EchoResponse.class);
assertThat(mismatchedDetail).isNull();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be better as a unit test inside ErrorDetailsTest and not as an IT.


// GAX HTTP/JSON parser limitation: Because the response contains a custom/unregistered type
// (PoetryError) in the Any details list, HttpJsonErrorParser fails to parse the status payload,
// resulting in empty/null ErrorDetails.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty/null ErrorInfo?

Comment on lines +187 to +188
// Workaround REST limitation: Parse the raw HTTP JSON error response manually using a custom
// TypeRegistry that registers standard types plus the showcase-specific PoetryError type.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comment to note: This mimics the behavior in HttpJsonErrorParser. HttpJsonErrorParser doesn't support passing in a custom TypeRegistry

@lqiu96

lqiu96 commented Jul 28, 2026

Copy link
Copy Markdown
Member

Lint issue looks external:

[ERROR] Failed to execute goal com.spotify.fmt:fmt-maven-plugin:2.25:check (default-cli) on project grpc-google-cloud-sql-v1: Found 6 non-complying files, failing build -> [Help 1]
[ERROR] Failed to execute goal com.spotify.fmt:fmt-maven-plugin:2.25:check (default-cli) on project grpc-google-cloud-sql-v1beta4: Found 1 non-complying files, failing build -> [Help 1]

Hmm, maybe we try and update the branch. Maybe got fixed in main

@lqiu96 lqiu96 changed the title test(showcase): add integration tests for error details test(showcase): Add gRPC and HttpJson Showcase ITs to verify Error Details Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants