From f7e5b0e1cf52e1aab683c75bd0b258c40dd74203 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Fri, 1 Mar 2024 23:40:30 +0000 Subject: [PATCH 1/2] feat: enhance exception messages with request IDs and metadata --- .../8571dd20-b6a8-4cab-9e2a-567e273a016f.json | 8 ++++++++ .../de403702-531d-4f43-bc33-aa5bc2fc000f.json | 8 ++++++++ .../s3/S3ErrorMetadataIntegration.kt | 12 ++++++++++-- gradle/libs.versions.toml | 4 ++-- .../GetBucketLocationOperationDeserializerTest.kt | 2 +- .../s3/internal/Handle200ErrorsInterceptorTest.kt | 15 +++++++++------ 6 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 .changes/8571dd20-b6a8-4cab-9e2a-567e273a016f.json create mode 100644 .changes/de403702-531d-4f43-bc33-aa5bc2fc000f.json diff --git a/.changes/8571dd20-b6a8-4cab-9e2a-567e273a016f.json b/.changes/8571dd20-b6a8-4cab-9e2a-567e273a016f.json new file mode 100644 index 00000000000..66bb19be561 --- /dev/null +++ b/.changes/8571dd20-b6a8-4cab-9e2a-567e273a016f.json @@ -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" + ] +} \ No newline at end of file diff --git a/.changes/de403702-531d-4f43-bc33-aa5bc2fc000f.json b/.changes/de403702-531d-4f43-bc33-aa5bc2fc000f.json new file mode 100644 index 00000000000..9be9250e2c0 --- /dev/null +++ b/.changes/de403702-531d-4f43-bc33-aa5bc2fc000f.json @@ -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" + ] +} diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt index cde0f078d26..d9e80a59f30 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt @@ -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", "") { + withBlock("get() =", "") { + write("super.displayMetadata + ") + write("""listOfNotNull(sdkErrorMetadata.requestId2?.let { "Extended request ID: ${'$'}it" })""") + } + } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f19bf376040..5a16019fc1b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" diff --git a/services/s3/common/test/aws/sdk/kotlin/services/s3/internal/GetBucketLocationOperationDeserializerTest.kt b/services/s3/common/test/aws/sdk/kotlin/services/s3/internal/GetBucketLocationOperationDeserializerTest.kt index 2d8cff75d01..4d48f09a656 100644 --- a/services/s3/common/test/aws/sdk/kotlin/services/s3/internal/GetBucketLocationOperationDeserializerTest.kt +++ b/services/s3/common/test/aws/sdk/kotlin/services/s3/internal/GetBucketLocationOperationDeserializerTest.kt @@ -67,6 +67,6 @@ class GetBucketLocationOperationDeserializerTest { } } - assertEquals("Some message", exception.message) + assertEquals("Some message, Request ID: Some request ID", exception.message) } } diff --git a/services/s3/common/test/aws/sdk/kotlin/services/s3/internal/Handle200ErrorsInterceptorTest.kt b/services/s3/common/test/aws/sdk/kotlin/services/s3/internal/Handle200ErrorsInterceptorTest.kt index 2fb82260a37..a5541b6ab59 100644 --- a/services/s3/common/test/aws/sdk/kotlin/services/s3/internal/Handle200ErrorsInterceptorTest.kt +++ b/services/s3/common/test/aws/sdk/kotlin/services/s3/internal/Handle200ErrorsInterceptorTest.kt @@ -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 { @@ -29,8 +32,8 @@ class Handle200ErrorsInterceptorTest { SlowDown Please reduce your request rate. - K2H6N7ZGQT6WHCEG - WWoZlnK4pTjKCYn6eNV7GgOurabfqLkjbSyqTvDMGBaI9uwzyNhSaDhOCPs8paFGye7S6b/AB3A= + $REQUEST_ID + $EXT_REQUEST_ID """.trimIndent().encodeToByteArray() @@ -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 @@ -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) From 3e8afc6a11814cd9ba574daab0e7f79262f52a4b Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Fri, 8 Mar 2024 00:10:20 +0000 Subject: [PATCH 2/2] update smithy-kotlin version --- gradle/libs.versions.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5a16019fc1b..665a4462c08 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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.17-SNAPSHOT" -smithy-kotlin-codegen-version = "0.30.18-SNAPSHOT" +smithy-kotlin-runtime-version = "1.0.17" +smithy-kotlin-codegen-version = "0.30.18" # codegen smithy-version = "1.42.0"