From 5991a82309c9b6989ba6c30ee33952b2f75394c6 Mon Sep 17 00:00:00 2001 From: Cortez Page Date: Mon, 5 Apr 2021 18:28:14 -0700 Subject: [PATCH 1/5] add reason to CfnNotStabilizedException --- .../exceptions/CfnNotStabilizedException.java | 52 ++++++++++++++++++- .../proxy/ExceptionMessages.java | 2 +- .../CfnNotStabilizedExceptionTests.java | 8 +-- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java index 071e2681..1aa88a16 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java @@ -25,14 +25,62 @@ public CfnNotStabilizedException(final Throwable cause) { super(cause, ERROR_CODE); } + /** + * @param resourceTypeName + * @param resourceIdentifier + * @param reason Reason why the resource did not stabilize. This should include the current and + * desired state. + * + * Example: "Exceeded retry limit for DescribeResourceStatus. + * Current Value: IN_PROGRESS. Desired Value: COMPLETE." + */ + public CfnNotStabilizedException(final String resourceTypeName, + final String resourceIdentifier, + final String reason) { + this(resourceTypeName, resourceIdentifier, reason, null); + } + + /** + * @param resourceTypeName + * @param resourceIdentifier + * @param reason Reason why the resource did not stabilize. This should include the current and + * desired state. + * + * Example: "Exceeded retry limit for DescribeResourceStatus. + * Current Value: IN_PROGRESS. Desired Value: COMPLETE." + * @param cause + */ + public CfnNotStabilizedException(final String resourceTypeName, + final String resourceIdentifier, + final String reason, + final Throwable cause) { + super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier, reason), + cause, ERROR_CODE); + } + + /** + * use {@link #CfnNotStabilizedException(String, String, String)} + * + * @param resourceTypeName + * @param resourceIdentifier + */ + @Deprecated public CfnNotStabilizedException(final String resourceTypeName, final String resourceIdentifier) { - this(resourceTypeName, resourceIdentifier, null); + this(resourceTypeName, resourceIdentifier, (Throwable) null); } + /** + * use {@link #CfnNotStabilizedException(String, String, String, Throwable)} + * + * @param resourceTypeName + * @param resourceIdentifier + * @param cause + */ + @Deprecated public CfnNotStabilizedException(final String resourceTypeName, final String resourceIdentifier, final Throwable cause) { - super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier), cause, ERROR_CODE); + this(resourceTypeName, resourceIdentifier, "", cause); } } diff --git a/src/main/java/software/amazon/cloudformation/proxy/ExceptionMessages.java b/src/main/java/software/amazon/cloudformation/proxy/ExceptionMessages.java index f9d0d101..4616d6c8 100644 --- a/src/main/java/software/amazon/cloudformation/proxy/ExceptionMessages.java +++ b/src/main/java/software/amazon/cloudformation/proxy/ExceptionMessages.java @@ -23,7 +23,7 @@ final class ExceptionMessages { static final String INVALID_REQUEST = "Invalid request provided: %s"; static final String NETWORK_FAILURE = "Network failure occurred during operation '%s'."; static final String NOT_FOUND = "Resource of type '%s' with identifier '%s' was not found."; - static final String NOT_STABILIZED = "Resource of type '%s' with identifier '%s' did not stabilize."; + static final String NOT_STABILIZED = "Resource of type '%s' with identifier '%s' did not stabilize. %s"; static final String NOT_UPDATABLE = "Resource of type '%s' with identifier '%s' is not updatable with parameters provided."; static final String RESOURCE_CONFLICT = "Resource of type '%s' with identifier '%s' has a conflict. Reason: %s."; static final String SERVICE_INTERNAL_ERROR = "Internal error reported from downstream service during operation '%s'."; diff --git a/src/test/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedExceptionTests.java b/src/test/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedExceptionTests.java index 4c9ec051..32855f2a 100644 --- a/src/test/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedExceptionTests.java +++ b/src/test/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedExceptionTests.java @@ -23,9 +23,9 @@ public class CfnNotStabilizedExceptionTests { @Test public void cfnNotStabilizedException_isBaseHandlerException() { assertThatExceptionOfType(BaseHandlerException.class).isThrownBy(() -> { - throw new CfnNotStabilizedException("AWS::Type::Resource", "myId", new RuntimeException()); + throw new CfnNotStabilizedException("AWS::Type::Resource", "myId", "Reason", new RuntimeException()); }).withCauseInstanceOf(RuntimeException.class).withMessageContaining("AWS::Type::Resource").withMessageContaining("myId") - .withMessageContaining("not stabilize"); + .withMessageContaining("not stabilize").withMessageContaining("Reason"); } @Test @@ -38,9 +38,9 @@ public void cfnNotStabilizedException_singleArgConstructorHasNoMessage() { @Test public void cfnNotStabilizedException_noCauseGiven() { assertThatExceptionOfType(CfnNotStabilizedException.class).isThrownBy(() -> { - throw new CfnNotStabilizedException("AWS::Type::Resource", "myId"); + throw new CfnNotStabilizedException("AWS::Type::Resource", "myId", "Reason"); }).withNoCause().withMessageContaining("AWS::Type::Resource").withMessageContaining("myId") - .withMessageContaining("not stabilize"); + .withMessageContaining("not stabilize").withMessageContaining("Reason"); } @Test From 8a3b30623ee8e9d6b9f006adcedd60301c453895 Mon Sep 17 00:00:00 2001 From: Cortez Page Date: Wed, 14 Apr 2021 17:09:22 -0700 Subject: [PATCH 2/5] readd tests for deprecated constructors for CfnNotStabilizedException --- .../CfnNotStabilizedExceptionTests.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedExceptionTests.java b/src/test/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedExceptionTests.java index 32855f2a..8bbaa6bc 100644 --- a/src/test/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedExceptionTests.java +++ b/src/test/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedExceptionTests.java @@ -56,4 +56,22 @@ public void cfnNotStabilizedException_errorMessage() { throw new CfnNotStabilizedException(new RuntimeException("something wrong")); }).satisfies(exception -> assertEquals("something wrong", exception.getMessage())); } + + @Deprecated + @Test + public void cfnNotStabilizedExceptionWithoutReason_isBaseHandlerException() { + assertThatExceptionOfType(BaseHandlerException.class).isThrownBy(() -> { + throw new CfnNotStabilizedException("AWS::Type::Resource", "myId", new RuntimeException()); + }).withCauseInstanceOf(RuntimeException.class).withMessageContaining("AWS::Type::Resource").withMessageContaining("myId") + .withMessageContaining("not stabilize"); + } + + @Deprecated + @Test + public void cfnNotStabilizedExceptionWithoutReason_noCauseGiven() { + assertThatExceptionOfType(CfnNotStabilizedException.class).isThrownBy(() -> { + throw new CfnNotStabilizedException("AWS::Type::Resource", "myId"); + }).withNoCause().withMessageContaining("AWS::Type::Resource").withMessageContaining("myId") + .withMessageContaining("not stabilize"); + } } From 30ae2b54551a49990a2a231d30539b2c105cd5f8 Mon Sep 17 00:00:00 2001 From: Cortez Page Date: Wed, 28 Apr 2021 11:00:09 -0700 Subject: [PATCH 3/5] change CfnNotStabilizedException ctor reason param docs --- .../exceptions/CfnNotStabilizedException.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java index 1aa88a16..4374ce62 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java @@ -28,11 +28,12 @@ public CfnNotStabilizedException(final Throwable cause) { /** * @param resourceTypeName * @param resourceIdentifier - * @param reason Reason why the resource did not stabilize. This should include the current and - * desired state. + * @param reason Reason why the resource did not stabilize. This should include the current + * state. For AWS resources, this should include the relevant API Action name in + * IAM format and the RequestId * - * Example: "Exceeded retry limit for DescribeResourceStatus. - * Current Value: IN_PROGRESS. Desired Value: COMPLETE." + * Example: "Current Status: modifying (API: rds:DescribeDBClusters, + * RequestId: d682b02c-1383-11b4-a6bb-172dfac7f170)" */ public CfnNotStabilizedException(final String resourceTypeName, final String resourceIdentifier, @@ -43,11 +44,12 @@ public CfnNotStabilizedException(final String resourceTypeName, /** * @param resourceTypeName * @param resourceIdentifier - * @param reason Reason why the resource did not stabilize. This should include the current and - * desired state. + * @param reason Reason why the resource did not stabilize. This should include the current + * state. For AWS resources, this should include the relevant API Action name in + * IAM format and the RequestId * - * Example: "Exceeded retry limit for DescribeResourceStatus. - * Current Value: IN_PROGRESS. Desired Value: COMPLETE." + * Example: "Current Status: modifying (API: rds:DescribeDBClusters, + * RequestId: d682b02c-1383-11b4-a6bb-172dfac7f170)" * @param cause */ public CfnNotStabilizedException(final String resourceTypeName, From 2a82d928d4414c6702ba245b414cbd7cb2cf9bc5 Mon Sep 17 00:00:00 2001 From: Cortez Page Date: Wed, 28 Apr 2021 14:08:04 -0700 Subject: [PATCH 4/5] fix consider-using-with --- tests/test_codegen.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_codegen.py b/tests/test_codegen.py index 3c7d985c..fc13b883 100644 --- a/tests/test_codegen.py +++ b/tests/test_codegen.py @@ -177,9 +177,8 @@ def test_generate_without_java_plugin_in_pom_should_not_fail(project): def test__get_plugin_version_invalid_pom(project): - pom = open(project.root / "pom.xml", "w") - pom.write("invalid pom") - pom.close() + with open(project.root / "pom.xml", "w") as pom: + pom.write("invalid pom") with pytest.raises(InvalidMavenPOMError): project._plugin._get_java_plugin_dependency_version(project) From fa14c86f15b4033e1f7a64f139a72c846c0e7467 Mon Sep 17 00:00:00 2001 From: Cortez Page Date: Wed, 28 Apr 2021 15:20:37 -0700 Subject: [PATCH 5/5] remove duplicate doc entry --- .../exceptions/CfnNotStabilizedException.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java index 4374ce62..d1cf6427 100644 --- a/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java +++ b/src/main/java/software/amazon/cloudformation/exceptions/CfnNotStabilizedException.java @@ -25,16 +25,6 @@ public CfnNotStabilizedException(final Throwable cause) { super(cause, ERROR_CODE); } - /** - * @param resourceTypeName - * @param resourceIdentifier - * @param reason Reason why the resource did not stabilize. This should include the current - * state. For AWS resources, this should include the relevant API Action name in - * IAM format and the RequestId - * - * Example: "Current Status: modifying (API: rds:DescribeDBClusters, - * RequestId: d682b02c-1383-11b4-a6bb-172dfac7f170)" - */ public CfnNotStabilizedException(final String resourceTypeName, final String resourceIdentifier, final String reason) {