Skip to content

Commit

Permalink
Merge pull request #15705 from cdapio/CDAP-21059-error-management-and…
Browse files Browse the repository at this point in the history
…-classification

[CDAP-21059] Introduce a way to identify errors coming from dependent service
  • Loading branch information
itsankit-google authored Sep 17, 2024
2 parents 7292c8c + bf75e57 commit 6f4024b
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,24 @@
* 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>
* <li><b>dependency:</b> A boolean value indicating whether the error is coming from a
* dependent service.</li>
* </ul>
**/
public class ProgramFailureException extends RuntimeException {
private final ErrorCategory errorCategory;
private final String errorReason;
private final ErrorType errorType;
private final boolean dependency;

// Private constructor to prevent direct instantiation
private ProgramFailureException(ErrorCategory errorCategory, String errorMessage, String errorReason,
ErrorType errorType, Throwable cause) {
private ProgramFailureException(ErrorCategory errorCategory, String errorMessage,
String errorReason, ErrorType errorType, Throwable cause, boolean dependency) {
super(errorMessage, cause);
this.errorCategory = errorCategory;
this.errorReason = errorReason;
this.errorType = errorType;
this.dependency = dependency;
}

/**
Expand Down Expand Up @@ -87,6 +91,15 @@ public ErrorType getErrorType() {
return errorType == null ? ErrorType.UNKNOWN : errorType;
}

/**
* Returns whether the error is coming from a dependent service.
*
* @return true if the error is a dependency service error, false otherwise.
*/
public boolean isDependency() {
return dependency;
}

/**
* Builder class for ProgramFailureException.
*/
Expand All @@ -96,6 +109,7 @@ public static class Builder {
private String errorReason;
private ErrorType errorType;
private Throwable cause;
private boolean dependency;

/**
* Sets the error category for the ProgramFailureException.
Expand Down Expand Up @@ -152,14 +166,19 @@ public Builder withCause(Throwable cause) {
return this;
}

public Builder withDependency(boolean dependency) {
this.dependency = dependency;
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, cause);
errorReason, errorType, cause, dependency);
}
}
}

0 comments on commit 6f4024b

Please sign in to comment.