Skip to content

add reason to CfnNotStabilizedException #364

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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,62 @@ 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 and
* desired state.
*
* Example: "Exceeded retry limit for DescribeResourceStatus.
* Current Value: IN_PROGRESS. Desired Value: COMPLETE."
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, I like the docs and providing an example. Couple comments:

  • I don't think desired state is necessary
  • For AWS resources, it should include the current state, Api name in iam format (like ec2:DescribeInstances) and the RequestId for that API (for non AWS resources it would be whatever the equivalent debugging info)

The example here is also a little bit confusing. Is this one example or two examples? Here's one

* Instance Status: pending (Api: ec2:DescribeInstances, RequestId: abcd-efgh-ijkl)
* Current Status: modifying (Api: rds:DescribeDBClusters, RequestId: abcd-efgh-ijkl)

Another option here would be to take the apiName and requestid as parameters

*/
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);
}
}
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");
}
}