Skip to content
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

add reason to CfnNotStabilizedException #364

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,64 @@ public CfnNotStabilizedException(final Throwable cause) {
super(cause, ERROR_CODE);
}

/**
* @param resourceTypeName
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can remove this duplicate doc entry

* @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) {
this(resourceTypeName, resourceIdentifier, reason, null);
}

/**
* @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)"
* @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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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");
}
}
5 changes: 2 additions & 3 deletions tests/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down