-
Notifications
You must be signed in to change notification settings - Fork 882
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
Updating SDK exceptions #301
Conversation
} | ||
|
||
private AmazonServiceException createAse(HttpResponse errorResponse) throws Exception { | ||
private SdkServiceException createAse(HttpResponse errorResponse) throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might want to rename this method since it's not returning AmazonServiceException
anymore. createServiceException
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or createSse, that won't be ambiguous at all ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yep, will update. Thought I had most of them but found a new set. Hard to find all the cases of "ase" and all of it's casing throughout the code.
for (Unmarshaller<SdkServiceException, Node> unmarshaller : unmarshallerList) { | ||
SdkServiceException exception = unmarshaller.unmarshall(document); | ||
if (exception != null) { | ||
exception.statusCode(errorResponse.getStatusCode()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could errorResponse
be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not currently aware of a real case where it could be null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not massively expensive nor that big a maintenance burden - prolly just leave it in for now.
} | ||
|
||
public void headers(Map<String, String> headers) { | ||
this.headers = headers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use unmodifiableMap here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will update
.beginControlFlow("catch (AmazonServiceException ase)") | ||
.beginControlFlow("if (ase.getErrorCode().equals($S) && ase.getStatusCode() == 412)", | ||
.beginControlFlow("catch (SdkServiceException exception)") | ||
.beginControlFlow("if (exception.errorCode().equals($S) && ase.statusCode() == 412)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ase.statusCode() -> exception.statusCode()
ase has been renamed to exception.
Similarly in line 76
@@ -15,7 +15,7 @@ | |||
|
|||
package software.amazon.awssdk.codegen.protocol; | |||
|
|||
import software.amazon.awssdk.core.SdkBaseException; | |||
import software.amazon.awssdk.core.exception.SdkServiceException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be SdkException?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. The base exception for service exceptions is SdkServiceException
public AbortedException() { | ||
super(""); | ||
public AbortedException(Throwable cause) { | ||
super(null, cause); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why null here while line 31 uses "Aborted"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add it back in but this is what the prior defaults were.
Nothing -> just message "Aborted."
Message -> just message
Cause -> Just cause (message = null)
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* An aborted exception is not intended to be retried. | ||
*/ | ||
@Override | ||
public boolean isRetryable() { | ||
public boolean retryable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think we need this method here. SdkException by default returns false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
@@ -30,7 +40,7 @@ public ResetException(String message, Throwable t) { | |||
* A stream reset exception cannot be retried. | |||
*/ | |||
@Override | |||
public boolean isRetryable() { | |||
public boolean retryable() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above. can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
ase.setErrorType(AmazonServiceException.ErrorType.Service); | ||
} else if (errorType.equalsIgnoreCase("Sender")) { | ||
ase.setErrorType(AmazonServiceException.ErrorType.Client); | ||
if ("Receiver".equals(errorType)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do the values "Receiver" and "Sender"? Also document it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add documentation.
bd6510d
to
d17a518
Compare
@@ -89,6 +89,10 @@ private OutputT handleSuccessResponse(HttpResponse httpResponse, RequestExecutio | |||
} catch (IOException | InterruptedException | RetryableException e) { | |||
throw e; | |||
} catch (Exception e) { | |||
if (e instanceof SdkException && ((SdkException) e).retryable()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could successResponseHandler.handle
throw SdkException
? I looked at some implementations but didn't find any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could with S3.
Maybe when using lambdas as well but not sure on that.
exception.setStatusCode(statusCode); | ||
exception.setErrorType(AmazonServiceException.ErrorType.Client); | ||
exception.setErrorCode("Request entity too large"); | ||
SdkServiceException exception = new SdkServiceException("Request entity too large"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be a SdkClientException
since it's a client error? would it retry if we use SdkServiceException
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. We still pull out the status code and status text associated with the response from the service. The SdkClientException doesn't have these fields. It also doesn't portray as well that the request was made and the service rejected it as the clients fault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually thinking this might be dead code. The error response handler should always be able to throw an unmarshalled exception no matter what happens.
LGTM! don't forget to add changelog and good luck with merging conflicts..🙂 |
d17a518
to
d78ebce
Compare
Here's my general customer focused feedback, haven't looked at the code yet.
|
*/ | ||
public class Crc32MismatchException extends IOException { | ||
@SdkPublicApi | ||
public class Crc32MismatchException extends SdkClientException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Questioning why we don't retry this. Seems like a good candidate.
|
||
/** | ||
* Exception that is NOT retried in default retry policies. | ||
* Extension of {@link SdkException} that can be used by clients to | ||
* explicitly have an exception not retried. This exception will never be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last sentence here confuses me.
@@ -107,11 +107,11 @@ private RetryExecutor(SdkHttpFullRequest request, RequestExecutionContext contex | |||
} else { | |||
retryHandler.setLastRetriedException(handleUnmarshalledException(response)); | |||
} | |||
} catch (AmazonServiceException e) { | |||
} catch (SdkServiceException e) { | |||
// TODO This can be cleaned up a bit if we have separate hierarchies for service and client exceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we address this now?
return ase; | ||
public SdkServiceException handle(HttpResponse response, | ||
ExecutionAttributes executionAttributes) throws Exception { | ||
final SdkServiceException exception = (SdkServiceException) handleServiceException(response, executionAttributes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there something we can do about the case here? If not it's not a big deal.
exception.setStatusCode(statusCode); | ||
exception.setErrorType(AmazonServiceException.ErrorType.Client); | ||
exception.setErrorCode("Request entity too large"); | ||
SdkServiceException exception = new SdkServiceException("Request entity too large"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually thinking this might be dead code. The error response handler should always be able to throw an unmarshalled exception no matter what happens.
exception.setStatusCode(statusCode); | ||
exception.setErrorType(AmazonServiceException.ErrorType.Service); | ||
exception.setErrorCode(response.getStatusText()); | ||
SdkServiceException exception = new SdkServiceException(response.getStatusText()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here I think this is dead code.
} | ||
|
||
/** | ||
* @deprecated In favor of {@link RetryUtils#isThrottlingException(SdkBaseException)} | ||
* @deprecated In favor of {@link RetryUtils#isThrottlingException(SdkException)} | ||
*/ | ||
@Deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we handle some of these deprecations now?
return ErrorType.CLIENT; | ||
} else { | ||
return ErrorType.fromValue(errorType); | ||
} | ||
} | ||
|
||
@ReviewBeforeRelease("We shouldn't have S3 speific code in core. Also the way this is doesn't" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this with Zoe's change? Or has that not been merged yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it got removed in my PR, which got merged after this. so that's old code you are seeing 🙂
Updates the exceptions used by the SDK. Lots of files here but mostly just updating to use the new exceptions. Part 1 of additional changes around exceptions.
Description
Removes AmazonClientException, AmazonServiceException, and SdkBaseException.
Adds SdkClientException, SdkServiceException and SdkException.
SdkClientException extends SdkException
SdkServiceException extends SdkException
SdkException has a retryable() method that will allow generated exceptions to override and set this value.
Also adds NonRetryableException and RetryableException which are meant to be used by customers to explicitly mark exceptions in interceptors or lambdas.
Testing
All unit tests pass and have been updated as needed.
Types of changes
Checklist
mvn install
succeedsLicense