Skip to content

HeadObjectOperationDeserializer throwHeadObjectError throws wrong S3Exception("Failed to parse response as restXml error") when payload was not null but empty #1463

@mumbi

Description

@mumbi

Describe the bug

private fun throwHeadObjectError(context: ExecutionContext, call: HttpCall, payload: ByteArray?): kotlin.Nothing {
    val wrappedResponse = call.response.withPayload(payload)
    val wrappedCall = call.copy(response = wrappedResponse)

    val errorDetails = try {
        if (payload == null) {
            if (call.response.status == HttpStatusCode.NotFound) {
                S3ErrorDetails(code = "NotFound")

            } else {
                S3ErrorDetails(code = call.response.status.toString())

            }
        } else {
            parseS3ErrorResponse(payload)

        }
    } catch (ex: Exception) {
        throw S3Exception("Failed to parse response as restXml error").also {
            setS3ErrorMetadata(it, wrappedCall.response, null)
        }
    }
    val ex = when(errorDetails.code) {
        "NotFound" -> NotFoundDeserializer().deserialize(context, wrappedCall, payload)
        else -> S3Exception(errorDetails.message)
    }

    setS3ErrorMetadata(ex, wrappedResponse, errorDetails)
    throw ex
}

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected behavior

must throws NotFound exception when receive status 404

Current behavior

when receive status 404, sometimes payload is not null but empty.

when payload is not null, try to parse payload then throw S3Exception("Failed to parse response as restXml error")

Steps to Reproduce

head object from removed object

Possible Solution

No response

Context

No response

AWS SDK for Kotlin version

aws.sdk.kotlin:s3:1.3.70

Platform (JVM/JS/Native)

JVM

Operating system and version

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.closed-for-stalenessp2This is a standard priority issueresponse-requestedWaiting on additional info and feedback. Will move to 'closing-soon' in 5 days.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions