Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

CopyObjectAsync method throws AmazonS3Exception when source object doesn't exist. #2995

Closed
olizarevichroman opened this issue Jul 11, 2023 · 1 comment
Labels
bug This issue is a bug. s3

Comments

@olizarevichroman
Copy link

Describe the bug

When trying to copy not existing object s3 client throws an exception with error code NoSuchKey and CopyObjectResponse is null.

Expected Behavior

I would say we should provide error in CopyObjectRequest. At least we should set an appropriate http status code.

Also it's not clear how a library consumer should determine that it's an issue with source key, cause the only way I see here is to check that ErrorCode == "NoSuchKey" what seems weird.

Current Behavior

Amazon.S3.AmazonS3Exception: The specified key does not exist.
 ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
   at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
   at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RedirectHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   --- End of inner exception stack trace ---
   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)
   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception)
   at Amazon.Runtime.Internal.ExceptionHandler`1.HandleAsync(IExecutionContext executionContext, Exception exception)
   at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)

Reproduction Steps

Execute CopyObjectAsync on s3 client passing not existing SourceKey.

Possible Solution

Don't throw an exception but pass error context into CopyObjectResponse object

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.S3 3.7.107.5

Targeted .NET Platform

.NET 7

Operating System and version

OSX Ventura 13.4.1

@olizarevichroman olizarevichroman added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 11, 2023
@ashishdhingra
Copy link
Contributor

@olizarevichroman Good morning. Thanks for reporting the concern. The behavior to throw an exception is as per design. The behavior is also controlled by service models which may define what exceptions a particular service operation may throw (for example NoSuchKey). This behavior is uniform across all AWS SDK(s) and is unlikely to change.

For your use case, you may develop a middleware with POCO object for each service operation that could have a shape with members like StatusCode and <ServiceOperation>Response object, where your middleware would catch specific exceptions and returns POCO object with specified status code to the caller.

I'm converting this to Q&A discussion since the behavior is unlikely to change and is as per design.

Thanks,
Ashish

@ashishdhingra ashishdhingra removed the needs-triage This issue or PR still needs to be triaged. label Jul 11, 2023
@aws aws locked and limited conversation to collaborators Jul 11, 2023
@ashishdhingra ashishdhingra converted this issue into discussion #2996 Jul 11, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
bug This issue is a bug. s3
Projects
None yet
Development

No branches or pull requests

2 participants