-
Notifications
You must be signed in to change notification settings - Fork 39
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
More Error Info #683
More Error Info #683
Changes from 2 commits
c15a432
b5d4566
6a65b05
1397a9f
ec37170
f3c2934
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
package software.amazon.awssdk.crt; | ||
|
||
import static software.amazon.awssdk.crt.CRT.awsErrorName; | ||
import static software.amazon.awssdk.crt.CRT.awsErrorString; | ||
|
||
/** | ||
* This enum contains errors that need to be explicitly handled on the Java side of the JNI boundary. | ||
* Any time someone needs to respond to specific errorCodes, they should be added here | ||
* , so they'll at least | ||
* be in a central place. | ||
*/ | ||
public enum CrtErrorInfo { | ||
Success(0), | ||
TLSNegotiationFailure(1029), | ||
/** | ||
* We didn't know what it was, and need a way to know that. | ||
*/ | ||
UnKnownError(Integer.MAX_VALUE); | ||
waahm7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private int errorCode = 0; | ||
|
||
CrtErrorInfo(int errorCode) { | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public int getErrorCode() { | ||
return errorCode; | ||
} | ||
|
||
public String getAwsErrorString() { | ||
return awsErrorString(errorCode); | ||
} | ||
|
||
public String getAwsErrorName() { | ||
return awsErrorName(errorCode); | ||
} | ||
|
||
public boolean isModeledError() { | ||
return errorCode != UnKnownError.getErrorCode(); | ||
} | ||
|
||
public static CrtErrorInfo fromErrorCode(int errorCode) { | ||
for(CrtErrorInfo error : CrtErrorInfo.values()) { | ||
if (error.getErrorCode() == errorCode) { | ||
return error; | ||
} | ||
} | ||
|
||
return UnKnownError; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,14 @@ | |
package software.amazon.awssdk.crt.http; | ||
|
||
import software.amazon.awssdk.crt.CRT; | ||
import software.amazon.awssdk.crt.CrtErrorInfo; | ||
|
||
/** | ||
* This exception will be thrown by any exceptional cases encountered within the | ||
* JNI bindings to the AWS Common Runtime | ||
*/ | ||
public class HttpException extends RuntimeException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My real dream for aws-crt-java would be to code-gen actual exception classes (not just enums) so Java programmers could do the idiomatic thing and:
instead of:
But that would technically be a breaking change, since we'd be changing the exact exception classes that get raised 😓 Would it be worth breaking those eggs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deferring this convo to a later time. For now I can get by with the errir code being made public on the exception class |
||
private int errorCode; | ||
private final int errorCode; | ||
|
||
/** | ||
* Constructs a new HttpException | ||
|
@@ -24,11 +25,25 @@ public HttpException(int errorCode) { | |
} | ||
|
||
/** | ||
* Returns the error code captured when the exception occurred. This can be fed to {@link CRT.awsErrorString} to | ||
* Returns the error code captured when the exception occurred. This can be fed to {@link CRT.awsErrorName()} to | ||
* get a user-friendly error string | ||
* @return The error code associated with this exception | ||
*/ | ||
int getErrorCode() { | ||
public int getErrorCode() { | ||
return errorCode; | ||
} | ||
|
||
/** | ||
* Returns more detailed error info if it has been modeled. | ||
*/ | ||
public CrtErrorInfo getErrorInfo() { | ||
return CrtErrorInfo.fromErrorCode(errorCode); | ||
} | ||
|
||
/** | ||
* Returns true if this exception is retryable. | ||
*/ | ||
public boolean isRetryable() { | ||
return HttpClientConnection.isErrorRetryable(this); | ||
} | ||
} |
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.
We should code-gen these!
Waqar took a swing at doing this for aws-crt-swift a few months back. It didn't get merged for various reasons, but I'd love to take the cod-gen approach for errors in all CRTs:
Here's Waqar's code-genned enum list:
https://github.com/awslabs/aws-crt-swift/blob/fix-error-handling-2/Source/AwsCommonRuntimeKit/crt/CRTErrorGenerated.swift
Here's his code-gen script:
https://github.com/awslabs/aws-crt-swift/blob/fix-error-handling-2/Source/Script/CRTErrorGenerator.swift
We could have a CI step that confirms it's up to date (run script, fail if file changes)
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.
deferring this convo to a later time. For now I can get by with the errir code being made public on the exception class