Skip to content

Commit ee19684

Browse files
authored
fix: include more info for retry token bucket capacity errors (#1498)
1 parent ad7f245 commit ee19684

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "ab40d3c7-4701-47ee-87f5-985d68db8b7f",
3+
"type": "bugfix",
4+
"description": "Include more information when retry strategy halts early due to token bucket capacity errors",
5+
"issues": [
6+
"awslabs/aws-sdk-kotlin#1321"
7+
]
8+
}

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,8 @@ class S3ErrorMetadataIntegration : KotlinIntegration {
4848
}
4949
}
5050

51-
// SectionWriter to override the default sdkErrorMetadata and displayMetadata for S3's version
51+
// SectionWriter to override the default sdkErrorMetadata for S3's version
5252
private val addSdkErrorMetadataWriter = AppendingSectionWriter { writer ->
53-
writer
54-
.write("override val sdkErrorMetadata: S3ErrorMetadata = S3ErrorMetadata()")
55-
.write("")
56-
.withBlock("override val displayMetadata: List<String>", "") {
57-
withBlock("get() =", "") {
58-
write("super.displayMetadata + ")
59-
write("""listOfNotNull(sdkErrorMetadata.requestId2?.let { "Extended request ID: ${'$'}it" })""")
60-
}
61-
}
53+
writer.write("override val sdkErrorMetadata: S3ErrorMetadata = S3ErrorMetadata()")
6254
}
6355
}

services/s3/common/src/aws/sdk/kotlin/services/s3/internal/S3ErrorMetadata.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ package aws.sdk.kotlin.services.s3.internal
77
import aws.sdk.kotlin.runtime.AwsServiceException
88
import aws.sdk.kotlin.services.s3.model.S3ErrorMetadata
99
import aws.sdk.kotlin.services.s3.model.S3Exception
10+
import aws.smithy.kotlin.runtime.ClientErrorContext
11+
import aws.smithy.kotlin.runtime.ErrorMetadata
1012
import aws.smithy.kotlin.runtime.ServiceErrorMetadata
1113
import aws.smithy.kotlin.runtime.awsprotocol.AwsErrorDetails
1214
import aws.smithy.kotlin.runtime.awsprotocol.setAseErrorMetadata
15+
import aws.smithy.kotlin.runtime.collections.appendValue
1316
import aws.smithy.kotlin.runtime.collections.setIfValueNotNull
1417
import aws.smithy.kotlin.runtime.http.response.HttpResponse
1518
import aws.smithy.kotlin.runtime.serde.xml.data
@@ -33,12 +36,22 @@ internal data class S3ErrorDetails(
3336
*/
3437
internal fun setS3ErrorMetadata(exception: Any, response: HttpResponse, errorDetails: S3ErrorDetails?) {
3538
setAseErrorMetadata(exception, response, errorDetails)
39+
3640
if (exception is AwsServiceException) {
3741
exception.sdkErrorMetadata.attributes.setIfValueNotNull(ServiceErrorMetadata.RequestId, errorDetails?.requestId)
3842
}
43+
3944
if (exception is S3Exception) {
40-
val requestId2 = errorDetails?.requestId2 ?: response.headers[X_AMZN_REQUEST_ID_2_HEADER]
41-
exception.sdkErrorMetadata.attributes.setIfValueNotNull(S3ErrorMetadata.RequestId2, requestId2)
45+
(errorDetails?.requestId2 ?: response.headers[X_AMZN_REQUEST_ID_2_HEADER])?.let { requestId2 ->
46+
with(exception.sdkErrorMetadata) {
47+
attributes.setIfValueNotNull(S3ErrorMetadata.RequestId2, requestId2)
48+
49+
attributes.appendValue(
50+
ErrorMetadata.ClientContext,
51+
ClientErrorContext("Extended request ID", requestId2),
52+
)
53+
}
54+
}
4255
}
4356
}
4457

0 commit comments

Comments
 (0)