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

[CDAP-21059] fix the cause and error message of the exception so that it is propagated to parent #15694

Merged
Merged
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 @@ -32,19 +32,20 @@
* <li><b>errorReason:</b> A reason for why the error occurred.</li>
* <li><b>errorType:</b> The type of error, represented by the {@ErrorType} enum,
* such as SYSTEM, USER, or UNKNOWN.</li>
* <li><b>cause:</b> The cause of this throwable or null if the cause is nonexistent
* or unknown.</li>
* </ul>
**/
public class ProgramFailureException extends RuntimeException {
private final String errorCategory;
private final String errorMessage;
private final String errorReason;
private final ErrorType errorType;

// Private constructor to prevent direct instantiation
private ProgramFailureException(String errorCategory, String errorMessage, String errorReason,
ErrorType errorType) {
ErrorType errorType, Throwable cause) {
super(errorMessage, cause);
this.errorCategory = errorCategory;
this.errorMessage = errorMessage;
this.errorReason = errorReason;
this.errorType = errorType;
}
Expand All @@ -62,15 +63,6 @@ public String getErrorCategory() {
return errorCategory == null ? "Others" : errorCategory;
}

/**
* Returns the detailed message associated with the error.
*
* @return a {@String} representing the error message.
*/
public String getErrorMessage() {
return errorMessage;
}

/**
* Returns the reason for the error.
*
Expand Down Expand Up @@ -103,6 +95,7 @@ public static class Builder {
private String errorMessage;
private String errorReason;
private ErrorType errorType;
private Throwable cause;

/**
* Sets the error category for the ProgramFailureException.
Expand Down Expand Up @@ -148,13 +141,25 @@ public Builder withErrorType(ErrorType errorType) {
return this;
}

/**
* Sets the cause for the ProgramFailureException.
*
* @param cause the cause (which is saved for later retrieval by the getCause() method).
* @return The current Builder instance.
*/
public Builder withCause(Throwable cause) {
this.cause = cause;
return this;
}

/**
* Builds and returns a new instance of ProgramFailureException.
*
* @return A new ProgramFailureException instance.
*/
public ProgramFailureException build() {
return new ProgramFailureException(errorCategory, errorMessage, errorReason, errorType);
return new ProgramFailureException(errorCategory, errorMessage,
errorReason, errorType, cause);
}
}
}
Loading