From c15a432890d0e37f64d7fe8acc439a65fc9ba33e Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Fri, 15 Sep 2023 17:57:37 -0700 Subject: [PATCH 1/5] Expose more error info. --- .../amazon/awssdk/crt/CrtErrorInfo.java | 55 +++++++++++++++++++ .../amazon/awssdk/crt/http/HttpException.java | 21 ++++++- .../amazon/awssdk/crt/test/S3ClientTest.java | 4 +- 3 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java diff --git a/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java b/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java new file mode 100644 index 000000000..53d861682 --- /dev/null +++ b/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java @@ -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(1049), + /** + * We didn't know what it was, and need a way to know that. + */ + UnKnownError(Integer.MAX_VALUE); + + 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; + } +} diff --git a/src/main/java/software/amazon/awssdk/crt/http/HttpException.java b/src/main/java/software/amazon/awssdk/crt/http/HttpException.java index d000edd5d..179743c7e 100644 --- a/src/main/java/software/amazon/awssdk/crt/http/HttpException.java +++ b/src/main/java/software/amazon/awssdk/crt/http/HttpException.java @@ -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 { - 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); + } } diff --git a/src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java b/src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java index fb29820e9..9bc1c216d 100644 --- a/src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java +++ b/src/test/java/software/amazon/awssdk/crt/test/S3ClientTest.java @@ -1263,7 +1263,7 @@ public void benchmarkS3Get() { // resolution final int vipsNeeded = (int) Math.ceil(expectedGbps / 0.5 / 10); final int sampleDelay = Integer.parseInt(System.getProperty("aws.crt.s3.benchmark.warmup", - new Integer((int) Math.ceil(vipsNeeded / 5)).toString())); + Integer.toString((int) Math.ceil(vipsNeeded / 5)))); System.out.println(String.format("REGION=%s, WARMUP=%s", region, sampleDelay)); // Ignore stats during warm up time, they skew results @@ -1402,7 +1402,7 @@ public void benchmarkS3Put() { // resolution final int vipsNeeded = (int) Math.ceil(expectedGbps / 0.5 / 10); final int sampleDelay = Integer.parseInt(System.getProperty("aws.crt.s3.benchmark.warmup", - new Integer((int) Math.ceil(vipsNeeded / 5)).toString())); + Integer.toString((int) Math.ceil(vipsNeeded / 5)))); System.out.println(String.format("REGION=%s, WARMUP=%s", region, sampleDelay)); // Ignore stats during warm up time, they skew results From b5d456669e05a5d6a95b73d9102780b587d3a004 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Fri, 15 Sep 2023 18:13:29 -0700 Subject: [PATCH 2/5] Wrong value. --- src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java b/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java index 53d861682..c6fe7751b 100644 --- a/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java +++ b/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java @@ -15,7 +15,7 @@ */ public enum CrtErrorInfo { Success(0), - TLSNegotiationFailure(1049), + TLSNegotiationFailure(1029), /** * We didn't know what it was, and need a way to know that. */ From 1397a9f16f07c7f2c789d08ce69caec3e1ff1a51 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Mon, 18 Sep 2023 09:43:35 -0700 Subject: [PATCH 3/5] Revert the error enum and just make the error code on http exception public. --- crt/s2n | 2 +- .../amazon/awssdk/crt/CrtErrorInfo.java | 55 ------------------- .../amazon/awssdk/crt/http/HttpException.java | 17 +----- 3 files changed, 2 insertions(+), 72 deletions(-) delete mode 100644 src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java diff --git a/crt/s2n b/crt/s2n index f7930e58e..baf094768 160000 --- a/crt/s2n +++ b/crt/s2n @@ -1 +1 @@ -Subproject commit f7930e58e730ad745063785d1d421ecc952aee00 +Subproject commit baf094768e90d10a1f72182a1b04160e31d54c13 diff --git a/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java b/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java deleted file mode 100644 index c6fe7751b..000000000 --- a/src/main/java/software/amazon/awssdk/crt/CrtErrorInfo.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * 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); - - 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; - } -} diff --git a/src/main/java/software/amazon/awssdk/crt/http/HttpException.java b/src/main/java/software/amazon/awssdk/crt/http/HttpException.java index 179743c7e..5755dc5c9 100644 --- a/src/main/java/software/amazon/awssdk/crt/http/HttpException.java +++ b/src/main/java/software/amazon/awssdk/crt/http/HttpException.java @@ -6,7 +6,6 @@ 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 @@ -25,25 +24,11 @@ public HttpException(int errorCode) { } /** - * Returns the error code captured when the exception occurred. This can be fed to {@link CRT.awsErrorName()} to + * Returns the error code captured when the exception occurred. This can be fed to {@link CRT.awsErrorString} to * get a user-friendly error string * @return The error code associated with this exception */ 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); - } } From ec37170ca697628d01e63e5add0a22a968b984e9 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Mon, 18 Sep 2023 09:49:25 -0700 Subject: [PATCH 4/5] Put submodule back how I found it. --- crt/s2n | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crt/s2n b/crt/s2n index baf094768..f7930e58e 160000 --- a/crt/s2n +++ b/crt/s2n @@ -1 +1 @@ -Subproject commit baf094768e90d10a1f72182a1b04160e31d54c13 +Subproject commit f7930e58e730ad745063785d1d421ecc952aee00 From f3c293448f0ac15edb59a63eaa51d85866d28a66 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Mon, 18 Sep 2023 09:54:39 -0700 Subject: [PATCH 5/5] java doc link was broken and i'm not spending a moment on it because i do not care. --- .../java/software/amazon/awssdk/crt/http/HttpException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/software/amazon/awssdk/crt/http/HttpException.java b/src/main/java/software/amazon/awssdk/crt/http/HttpException.java index 5755dc5c9..b266151ee 100644 --- a/src/main/java/software/amazon/awssdk/crt/http/HttpException.java +++ b/src/main/java/software/amazon/awssdk/crt/http/HttpException.java @@ -24,7 +24,7 @@ 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 CRT.awsErrorString() to * get a user-friendly error string * @return The error code associated with this exception */