aws-sdk-kotlin icon indicating copy to clipboard operation
aws-sdk-kotlin copied to clipboard

Provide clear error when streaming body is consumed outside of closure

Open aajtodd opened this issue 2 years ago • 0 comments

Describe the feature

Streaming operations require that a user consumes the response completely inside a provided closure. It is easy to misuse these APIs though and attempt to return a reference to the streaming body.

Example today:

val stream = s3.getObject { resp -> resp.body }
val payload = stream.readAll() // error response body MUST be consumed inside the closure

The result of the above code depends on threading. Usually it will result in truncated reads which may or may not be caught right away.

The correct way to do the above:

val payload = s3.getObject { resp -> resp.body.readAll() }

We should try to provide a clear error when a streaming body is used outside of the closure.

Is your Feature Request related to a problem?

This was requested by a customer: https://github.com/awslabs/aws-sdk-kotlin/issues/594#issuecomment-1110358776

Proposed Solution

No response

Describe alternative solutions or features you've considered

No response

Acknowledge

  • [X] I may be able to implement this feature request

AWS Kotlin SDK version used

0.14.4-beta

Platform (JVM/JS/Native)

JVM

Operating System and version

N/A

aajtodd avatar Apr 27 '22 13:04 aajtodd