From cbb59c48d45d1684e09a582cacbc836e50e62049 Mon Sep 17 00:00:00 2001 From: Josh Humphries <2035234+jhump@users.noreply.github.com> Date: Tue, 9 Jan 2024 13:01:17 -0500 Subject: [PATCH] fix error message; add some TODOs --- .../kotlin/com/connectrpc/extensions/GoogleJavaJSONAdapter.kt | 2 ++ .../com/connectrpc/extensions/GoogleJavaJSONStrategy.kt | 2 +- .../com/connectrpc/extensions/GoogleJavaProtoAdapter.kt | 4 ++++ .../com/connectrpc/extensions/GoogleLiteProtoAdapter.kt | 4 ++++ .../main/kotlin/com/connectrpc/okhttp/ConnectOkHttpClient.kt | 3 +++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaJSONAdapter.kt b/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaJSONAdapter.kt index 8762237e..3fa7e347 100644 --- a/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaJSONAdapter.kt +++ b/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaJSONAdapter.kt @@ -64,6 +64,8 @@ internal class GoogleJavaJSONAdapter( if (deterministic) { printer = printer.sortingMapKeys() } + // TODO: It would likely be more efficient to use printer.appendTo + // with an Appendable implementation that wraps a Buffer. val jsonString = printer.print(message) return Buffer().write(jsonString.encodeUtf8()) } diff --git a/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaJSONStrategy.kt b/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaJSONStrategy.kt index 19713d49..70f74ef1 100644 --- a/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaJSONStrategy.kt +++ b/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaJSONStrategy.kt @@ -35,7 +35,7 @@ class GoogleJavaJSONStrategy( override fun codec(clazz: KClass): Codec { if (!clazz.isSubclassOf(Message::class)) { - throw RuntimeException("class ${clazz.qualifiedName} does not extend MessageLite") + throw RuntimeException("class ${clazz.qualifiedName} does not extend Message") } @Suppress("UNCHECKED_CAST") // we just checked above, so it's safe val messageClass = clazz as KClass diff --git a/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaProtoAdapter.kt b/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaProtoAdapter.kt index 5a18731f..a38d5f1f 100644 --- a/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaProtoAdapter.kt +++ b/extensions/google-java/src/main/kotlin/com/connectrpc/extensions/GoogleJavaProtoAdapter.kt @@ -54,6 +54,10 @@ internal class GoogleJavaProtoAdapter( } private fun serialize(message: E, deterministic: Boolean): Buffer { + // TODO: It would likely be more efficient to wrap a Buffer with + // an OutputStream implementation so we don't have to + // first create a separate byte array that gets copied to + // buffer. val result = ByteArray(message.serializedSize) val output = CodedOutputStream.newInstance(result) if (deterministic) { diff --git a/extensions/google-javalite/src/main/kotlin/com/connectrpc/extensions/GoogleLiteProtoAdapter.kt b/extensions/google-javalite/src/main/kotlin/com/connectrpc/extensions/GoogleLiteProtoAdapter.kt index 2b2c1d94..0bdd690d 100644 --- a/extensions/google-javalite/src/main/kotlin/com/connectrpc/extensions/GoogleLiteProtoAdapter.kt +++ b/extensions/google-javalite/src/main/kotlin/com/connectrpc/extensions/GoogleLiteProtoAdapter.kt @@ -54,6 +54,10 @@ internal class GoogleLiteProtoAdapter( } private fun serialize(message: E, deterministic: Boolean): Buffer { + // TODO: It would likely be more efficient to wrap a Buffer with + // an OutputStream implementation so we don't have to + // first create a separate byte array that gets copied to + // buffer. val result = ByteArray(message.serializedSize) val output = CodedOutputStream.newInstance(result) if (deterministic) { diff --git a/okhttp/src/main/kotlin/com/connectrpc/okhttp/ConnectOkHttpClient.kt b/okhttp/src/main/kotlin/com/connectrpc/okhttp/ConnectOkHttpClient.kt index 66d5619a..658e2542 100644 --- a/okhttp/src/main/kotlin/com/connectrpc/okhttp/ConnectOkHttpClient.kt +++ b/okhttp/src/main/kotlin/com/connectrpc/okhttp/ConnectOkHttpClient.kt @@ -142,6 +142,9 @@ internal fun codeFromIOException(e: IOException): Code { ) { Code.DEADLINE_EXCEEDED } else if (e.message?.lowercase() == "canceled") { + // TODO: Figure out what, if anything, actually throws an exception + // with this message. It seems more likely that a JVM or + // Kotlin coroutine exception would spell it with two Ls. Code.CANCELED } else { Code.UNKNOWN