Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enhance exception messages with request IDs and metadata #1240

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changes/8571dd20-b6a8-4cab-9e2a-567e273a016f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "8571dd20-b6a8-4cab-9e2a-567e273a016f",
"type": "feature",
"description": "Add request IDs to exception messages where available",
"issues": [
"awslabs/aws-sdk-kotlin#1212"
]
}
8 changes: 8 additions & 0 deletions .changes/de403702-531d-4f43-bc33-aa5bc2fc000f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "de403702-531d-4f43-bc33-aa5bc2fc000f",
"type": "feature",
"description": "Add error metadata to ServiceException messages when a service-provided message isn't available",
"issues": [
"awslabs/aws-sdk-kotlin#1212"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@ class S3ErrorMetadataIntegration : KotlinIntegration {
}
}

// SectionWriter to override the default sdkErrorMetadata for S3's version
// SectionWriter to override the default sdkErrorMetadata and displayMetadata for S3's version
private val addSdkErrorMetadataWriter = AppendingSectionWriter { writer ->
writer.write("override val sdkErrorMetadata: S3ErrorMetadata = S3ErrorMetadata()")
writer
.write("override val sdkErrorMetadata: S3ErrorMetadata = S3ErrorMetadata()")
.write("")
.withBlock("override val displayMetadata: List<String>", "") {
withBlock("get() =", "") {
write("super.displayMetadata + ")
write("""listOfNotNull(sdkErrorMetadata.requestId2?.let { "Extended request ID: ${'$'}it" })""")
}
}
}
}
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ coroutines-version = "1.7.3"
atomicfu-version = "0.23.1"

# smithy-kotlin codegen and runtime are versioned separately
smithy-kotlin-runtime-version = "1.0.16"
smithy-kotlin-codegen-version = "0.30.17"
smithy-kotlin-runtime-version = "1.0.17-SNAPSHOT"
smithy-kotlin-codegen-version = "0.30.18-SNAPSHOT"

# codegen
smithy-version = "1.42.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ class GetBucketLocationOperationDeserializerTest {
}
}

assertEquals("Some message", exception.message)
assertEquals("Some message, Request ID: Some request ID", exception.message)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

private const val REQUEST_ID = "K2H6N7ZGQT6WHCEG"
private const val EXT_REQUEST_ID = "WWoZlnK4pTjKCYn6eNV7GgOurabfqLkjbSyqTvDMGBaI9uwzyNhSaDhOCPs8paFGye7S6b/AB3A="

class Handle200ErrorsInterceptorTest {

object TestCredentialsProvider : CredentialsProvider {
Expand All @@ -29,8 +32,8 @@ class Handle200ErrorsInterceptorTest {
<Error>
<Code>SlowDown</Code>
<Message>Please reduce your request rate.</Message>
<RequestId>K2H6N7ZGQT6WHCEG</RequestId>
<HostId>WWoZlnK4pTjKCYn6eNV7GgOurabfqLkjbSyqTvDMGBaI9uwzyNhSaDhOCPs8paFGye7S6b/AB3A=</HostId>
<RequestId>$REQUEST_ID</RequestId>
<HostId>$EXT_REQUEST_ID</HostId>
</Error>
""".trimIndent().encodeToByteArray()

Expand All @@ -53,9 +56,9 @@ class Handle200ErrorsInterceptorTest {
val expectedMessage = "Please reduce your request rate."
assertEquals("SlowDown", ex.sdkErrorMetadata.errorCode)
assertEquals(expectedMessage, ex.sdkErrorMetadata.errorMessage)
assertEquals(expectedMessage, ex.message)
assertEquals("K2H6N7ZGQT6WHCEG", ex.sdkErrorMetadata.requestId)
assertEquals("WWoZlnK4pTjKCYn6eNV7GgOurabfqLkjbSyqTvDMGBaI9uwzyNhSaDhOCPs8paFGye7S6b/AB3A=", ex.sdkErrorMetadata.requestId2)
assertEquals("$expectedMessage, Request ID: $REQUEST_ID, Extended request ID: $EXT_REQUEST_ID", ex.message)
assertEquals(REQUEST_ID, ex.sdkErrorMetadata.requestId)
assertEquals(EXT_REQUEST_ID, ex.sdkErrorMetadata.requestId2)
}

@Test
Expand Down Expand Up @@ -107,7 +110,7 @@ class Handle200ErrorsInterceptorTest {
s3.deleteObjects { bucket = "test" }
}
val expectedMessage = "Please use less foos."
assertEquals(expectedMessage, ex.message)
assertEquals("$expectedMessage, Request ID: rid, Extended request ID: rid2", ex.message)
assertEquals(expectedMessage, ex.sdkErrorMetadata.errorMessage)
assertEquals("FooError", ex.sdkErrorMetadata.errorCode)
assertEquals("rid", ex.sdkErrorMetadata.requestId)
Expand Down
Loading