Skip to content

Wrap CrtS3RuntimeException to SdkServiceException #2558

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

Merged
merged 1 commit into from
Jun 28, 2021
Merged

Wrap CrtS3RuntimeException to SdkServiceException #2558

merged 1 commit into from
Jun 28, 2021

Conversation

joviegas
Copy link
Contributor

@joviegas joviegas commented Jun 25, 2021

Description

  • Wrap CrtS3RuntimeException to SdkServiceException

Motivation and Context

  • Currently CrtClient throws CrtS3RuntimeException whenever there is S3 Service side exceptions.
  • We need to Wrap these exception indicating these are Service side exceptions

Testing

  • Added Integration test
  • Added Junits

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

? crtS3RuntimeExceptionOptional
.filter(item -> StringUtils.isNotBlank(item.getAwsErrorCode())
|| StringUtils.isNotBlank(item.getAwsErrorMessage())).map(e -> SdkServiceException.builder()
.statusCode(crtS3RuntimeExceptionOptional.get().getStatusCode())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create specific S3Exception based on the error code?
For example:
NoSuchBucket -> NoSuchBucketException.

That way, customers can handle specific cases without checking the error code by themselves.

If the error code can't be mapped, I think we should just return a generic S3ServiceException

If there's no error code, we should wrap it with SdkClientException.

WDUT?

Copy link
Contributor Author

@joviegas joviegas Jun 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented to get Service side exception.This uses reflection.
We might need to update the CrtS3RuntimeException to send requestId so that service exception is built with this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write down each exception type rather than using reflection? I don't think there are many specific exceptions for get and put. https://github.com/aws/aws-sdk-java-v2/blob/master/services/s3/src/main/resources/codegen-resources/service-2.json#L509 In the future, we will generate the code. I think we should be very careful about using reflection.

public Exception transformException(Exception crtRuntimeException) {
Optional<CrtS3RuntimeException> crtS3RuntimeExceptionOptional = getCrtS3RuntimeException(crtRuntimeException);

return crtS3RuntimeExceptionOptional.isPresent()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: instead of checking if it's present and doing crtS3RuntimeExceptionOptional.get(), we can do the following:

return crtS3RuntimeExceptionOptional.filter(xxxx).orElse(crtRuntimeException)

Can we break up the code block within filter(xx)? It's a bit hard to read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

assertThatThrownBy(() -> s3Crt.getObject(GetObjectRequest.builder().bucket(BUCKET).key("randomKey").build(),
Paths.get(randomBaseDirectory).resolve("testFile")).get())
.hasCauseInstanceOf(SdkServiceException.class)
.hasMessageContaining("Failed with Aws Error code \"NoSuchKey\" and Aws Error Message \"The specified key does not exist.\"");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: we probably don't need to verify the whole message because services can change them, which will make the tests flaky.

Same as other tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this

@joviegas joviegas merged commit 893b493 into aws:feature/master/transfermanager Jun 28, 2021
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

87.1% 87.1% Coverage
0.0% 0.0% Duplication

aws-sdk-java-automation added a commit that referenced this pull request May 15, 2023
…3c5e5ce2e

Pull request: release <- staging/242be335-3287-4272-b0ff-0433c5e5ce2e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants