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

Fixed problem when original exception message was lost. #350

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -22,7 +22,7 @@ public abstract class BaseHandlerException extends RuntimeException {

private static final long serialVersionUID = -1646136434112354328L;

private HandlerErrorCode errorCode;
private final HandlerErrorCode errorCode;

protected BaseHandlerException(final Throwable cause,
final HandlerErrorCode errorCode) {
Expand All @@ -33,7 +33,7 @@ protected BaseHandlerException(final Throwable cause,
protected BaseHandlerException(final String message,
final Throwable cause,
final HandlerErrorCode errorCode) {
super(message, cause);
super(String.format("%s %s", message, cause.getMessage()), cause);
this.errorCode = errorCode;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CfnAccessDeniedException(final Throwable cause) {
}

public CfnAccessDeniedException(final String operation) {
this(operation, null);
super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE);
}

public CfnAccessDeniedException(final String operation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CfnAlreadyExistsException(final Throwable cause) {

public CfnAlreadyExistsException(final String resourceTypeName,
final String resourceIdentifier) {
this(resourceTypeName, resourceIdentifier, null);
super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier), ERROR_CODE);
}

public CfnAlreadyExistsException(final String resourceTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CfnGeneralServiceException(final Throwable cause) {
}

public CfnGeneralServiceException(final String operation) {
this(operation, null);
super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE);
}

public CfnGeneralServiceException(final String operation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class CfnInternalFailureException extends BaseHandlerException {
private static final HandlerErrorCode ERROR_CODE = HandlerErrorCode.InternalFailure;

public CfnInternalFailureException() {
this(null);
super(ERROR_CODE.getMessage(), ERROR_CODE);
}

public CfnInternalFailureException(final Throwable cause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CfnInvalidRequestException(final Throwable cause) {
}

public CfnInvalidRequestException(final String requestBody) {
this(requestBody, null);
super(String.format(ERROR_CODE.getMessage(), requestBody), ERROR_CODE);
}

public CfnInvalidRequestException(final String requestBody,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CfnNetworkFailureException(final Throwable cause) {
}

public CfnNetworkFailureException(final String operation) {
this(operation, null);
super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE);
}

public CfnNetworkFailureException(final String operation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CfnNotFoundException(final Throwable cause) {

public CfnNotFoundException(final String resourceTypeName,
final String resourceIdentifier) {
this(resourceTypeName, resourceIdentifier, null);
super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier), ERROR_CODE);
}

public CfnNotFoundException(final String resourceTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CfnNotStabilizedException(final Throwable cause) {

public CfnNotStabilizedException(final String resourceTypeName,
final String resourceIdentifier) {
this(resourceTypeName, resourceIdentifier, null);
super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier), ERROR_CODE);
}

public CfnNotStabilizedException(final String resourceTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CfnNotUpdatableException(final Throwable cause) {

public CfnNotUpdatableException(final String resourceTypeName,
final String resourceIdentifier) {
this(resourceTypeName, resourceIdentifier, null);
super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier), ERROR_CODE);
}

public CfnNotUpdatableException(final String resourceTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CfnResourceConflictException(final Throwable cause) {
public CfnResourceConflictException(final String resourceTypeName,
final String resourceIdentifier,
final String conflictReason) {
this(resourceTypeName, resourceIdentifier, conflictReason, null);
super(String.format(ERROR_CODE.getMessage(), resourceTypeName, resourceIdentifier, conflictReason), ERROR_CODE);
}

public CfnResourceConflictException(final String resourceTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CfnServiceInternalErrorException(final Throwable cause) {
}

public CfnServiceInternalErrorException(final String operation) {
this(operation, null);
super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE);
}

public CfnServiceInternalErrorException(final String operation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public CfnServiceLimitExceededException(final Throwable cause) {

public CfnServiceLimitExceededException(final String resourceTypeName,
final String reason) {
this(resourceTypeName, reason, null);
super(String.format(ERROR_CODE.getMessage(), resourceTypeName, reason), ERROR_CODE);
}

public CfnServiceLimitExceededException(final String resourceTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CfnThrottlingException(final Throwable cause) {
}

public CfnThrottlingException(final String operation) {
this(operation, null);
super(String.format(ERROR_CODE.getMessage(), operation), ERROR_CODE);
}

public CfnThrottlingException(final String operation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ResourceAlreadyExistsException(final Throwable cause) {

public ResourceAlreadyExistsException(final String resourceTypeName,
final String resourceIdentifier) {
this(resourceTypeName, resourceIdentifier, null);
super(resourceTypeName, resourceIdentifier);
}

public ResourceAlreadyExistsException(final String resourceTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ResourceNotFoundException(final Throwable cause) {

public ResourceNotFoundException(final String resourceTypeName,
final String resourceIdentifier) {
this(resourceTypeName, resourceIdentifier, null);
super(resourceTypeName, resourceIdentifier);
}

public ResourceNotFoundException(final String resourceTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,11 @@ public void cfnGeneralServiceException_errorMessage() {
throw new CfnGeneralServiceException(new RuntimeException("something wrong"));
}).satisfies(exception -> assertEquals("something wrong", exception.getMessage()));
}

@Test
public void cfnGeneralServiceException_detailedErrorMessage() {
assertThatExceptionOfType(CfnGeneralServiceException.class).isThrownBy(() -> {
throw new CfnGeneralServiceException("Some operation", new RuntimeException("something wrong"));
}).satisfies(exception -> assertEquals("Error occurred during operation 'Some operation'. something wrong", exception.getMessage()));
}
}