Skip to content

Add Wire's google.rpc error details - #3759

Merged
oldergod merged 5 commits into
masterfrom
bquenaudon/rpc-error-details
Nov 23, 2026
Merged

oldergod merged 5 commits into
masterfrom
bquenaudon/rpc-error-details

Conversation

@oldergod

@oldergod oldergod commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Stacked on #3758.

google.rpc.Status.details usually carries the standard payloads from google/rpc/error_details.proto.
Without them, users who want to read an ErrorInfo from a GrpcException must generate that file.
That brings back the com.google.rpc classpath conflict which #3758 fixes for Status.

  • wire-runtime: add ErrorInfo, RetryInfo, DebugInfo, QuotaFailure, PreconditionFailure, BadRequest, RequestInfo, ResourceInfo, Help and LocalizedMessage to com.squareup.wire.rpc, next to RpcStatus. The files are Wire's Kotlin output for error_details.proto with java_package set to com.squareup.wire.rpc. They import kotlin.jvm.JvmField instead of Wire's internal JvmField, so that ADAPTER is a static field on the JVM, as in AnyMessage. Type URLs stay type.googleapis.com/google.rpc.*.
  • wire-schema: bundle google/rpc/error_details.proto and list its 14 types (nested types included) in GOOGLE_RPC_ERROR_DETAILS_TYPES. A test checks this list against the bundled proto, and checks that each runtime class has a static ADAPTER with the right type URL.
  • Kotlin and Java generators: map these types to the runtime classes. Wire never generates its own copies.
catch (e: GrpcException) {
  val errorInfo = e.rpcStatus?.details?.firstNotNullOfOrNull { it.unpackOrNull(ErrorInfo.ADAPTER) }
}

To regenerate the runtime classes, copy error_details.proto and set package google.rpcx; and option java_package = "com.squareup.wire.rpc"; in the copy.
Wire skips the built-in google.rpc types, so the copy needs another package.
Then run:

./gradlew :wire-compiler:run --args="--proto_path=<copy> --kotlin_out=<out> google/rpc/error_details.proto"

Replace google.rpcx with google.rpc in the output, and replace Wire's internal JvmField import with import kotlin.jvm.JvmField.
Then copy the files to wire-runtime/src/commonMain/kotlin/com/squareup/wire/rpc.

Open questions:

  • Size. This adds 10 top-level classes to wire-runtime. R8 removes them when unused, but a separate artifact is also possible.
  • google.rpc.Code is not included, because GrpcStatus already covers the codes.
  • Swift is not changed.

Release note: ⚠ Breaking: Wire no longer generates the types of google/rpc/error_details.proto.
Fields of those types now use the classes in com.squareup.wire.rpc, such as ErrorInfo and BadRequest.FieldViolation.
Replace com.google.rpc.ErrorInfo and the other types, or your own java_package classes, with the com.squareup.wire.rpc classes.
The Proto target no longer emits google/rpc/error_details.proto.

@escardin escardin left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for doing this

@oldergod
oldergod marked this pull request as ready for review November 10, 2026 14:47
@oldergod
oldergod force-pushed the bquenaudon/rpc-status branch from 924d317 to fc75fbb Compare November 20, 2026 15:37
@oldergod
oldergod force-pushed the bquenaudon/rpc-error-details branch from 9c4c3a4 to 627c078 Compare November 20, 2026 15:37
Wire now bundles google/rpc/error_details.proto and ships its types in
com.squareup.wire.rpc: ErrorInfo, RetryInfo, DebugInfo, QuotaFailure,
PreconditionFailure, BadRequest, RequestInfo, ResourceInfo, Help and
LocalizedMessage. These are the usual payloads of RpcStatus.details.

The classes are Wire's Kotlin output for the proto with java_package
set to com.squareup.wire.rpc. Type URLs stay google.rpc. The Kotlin and
Java generators map the google.rpc types to these classes, so generated
code never makes its own copy.
Wire's Kotlin generator now defers merges of singular message fields and sanitizes map fields in toString().
This commit regenerates the checked-in error details classes so that they match that output.
@oldergod
oldergod force-pushed the bquenaudon/rpc-error-details branch from 627c078 to 2a318e1 Compare November 23, 2026 13:40
The generated files imported Wire's internal JvmField, which gives no static field inside wire-runtime. ProtoAdapter.get and the adapter strings in @WireField look up a static ADAPTER, so they failed for these types.
Base automatically changed from bquenaudon/rpc-status to master November 23, 2026 14:51
@oldergod
oldergod merged commit 3198f6e into master Nov 23, 2026
12 checks passed
@oldergod
oldergod deleted the bquenaudon/rpc-error-details branch November 23, 2026 15:01
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.

2 participants