-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce error details provider to get more information about except…
…ons from plugins
- Loading branch information
1 parent
61105ff
commit 938afb1
Showing
12 changed files
with
281 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...p-etl/cdap-etl-api/src/main/java/io/cdap/cdap/etl/api/exception/ErrorDetailsProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.api.exception; | ||
|
||
import io.cdap.cdap.api.exception.ProgramFailureException; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Interface for providing error details. | ||
* | ||
* <p> | ||
* Implementations of this interface can be used to provide more detailed error information | ||
* for exceptions that occur within the code using {@link ProgramFailureException}. | ||
* </p> | ||
*/ | ||
public interface ErrorDetailsProvider { | ||
public static final String EXCEPTION_DETAILS_CLASS_NAME_KEY = | ||
"io.cdap.pipeline.error.details.provider.classname"; | ||
|
||
/** | ||
* Returns a {@link RuntimeException} that wraps the given exception with more detailed | ||
* information. | ||
* | ||
* @param e the exception to wrap | ||
* @return {@link ProgramFailureException} that wraps the given exception with more detailed information. | ||
*/ | ||
@Nullable | ||
ProgramFailureException getExceptionDetails(Exception e, ErrorPhase phase); | ||
} |
42 changes: 42 additions & 0 deletions
42
...plates/cdap-etl/cdap-etl-api/src/main/java/io/cdap/cdap/etl/api/exception/ErrorPhase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
/** | ||
* Enum representing the different phases of a stage where error can occur. | ||
*/ | ||
package io.cdap.cdap.etl.api.exception; | ||
|
||
public enum ErrorPhase { | ||
GETTING_SPLITS( "Getting Splits"), | ||
READING_RECORDS("Reading Records"), | ||
CHECKING_OUTPUT_SPECS("Checking Output Specs"), | ||
WRITING_RECORDS("Writing Records"), | ||
COMMITTING_RECORDS("Committing Records"); | ||
|
||
private final String displayName; | ||
|
||
ErrorPhase(String displayName) { | ||
this.displayName = displayName; | ||
} | ||
|
||
/** | ||
* Returns a string representation of the error category enum. | ||
*/ | ||
@Override | ||
public String toString() { | ||
return displayName; | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...emplates/cdap-etl/cdap-etl-core/src/main/java/io/cdap/cdap/etl/common/ExceptionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright © 2024 Cask Data, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
package io.cdap.cdap.etl.common; | ||
|
||
import io.cdap.cdap.api.exception.ErrorCategory; | ||
import io.cdap.cdap.api.exception.ErrorCategory.ErrorCategoryEnum; | ||
import io.cdap.cdap.api.exception.ErrorType; | ||
import io.cdap.cdap.api.exception.ErrorUtils; | ||
import io.cdap.cdap.api.exception.ProgramFailureException; | ||
import io.cdap.cdap.api.exception.WrappedStageException; | ||
import io.cdap.cdap.etl.api.exception.ErrorDetailsProvider; | ||
import io.cdap.cdap.etl.api.exception.ErrorPhase; | ||
import javax.annotation.Nullable; | ||
import org.apache.hadoop.conf.Configuration; | ||
|
||
/** | ||
* Utility class for handling exceptions. | ||
*/ | ||
public class ExceptionUtils { | ||
|
||
/** | ||
* Gets the {@link ErrorDetailsProvider} from the given {@link Configuration}. | ||
* | ||
* @param conf the configuration to get the error details provider from. | ||
* @return the error details provider. | ||
*/ | ||
@Nullable | ||
public static ErrorDetailsProvider getErrorDetailsProvider(Configuration conf) { | ||
String errorDetailsProviderClassName = | ||
conf.get(ErrorDetailsProvider.EXCEPTION_DETAILS_CLASS_NAME_KEY); | ||
if (errorDetailsProviderClassName == null) { | ||
return null; | ||
} | ||
try { | ||
return (ErrorDetailsProvider) conf.getClassLoader() | ||
.loadClass(errorDetailsProviderClassName) | ||
.newInstance(); | ||
} catch (Exception e) { | ||
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategoryEnum.PLUGIN), | ||
String.format("Unable to instantiate errorDetailsProvider class '%s'.", | ||
errorDetailsProviderClassName), e.getMessage(), ErrorType.SYSTEM, false, e); | ||
} | ||
} | ||
|
||
/** | ||
* Handles the given exception, wrapping it in a {@link WrappedStageException}. | ||
* | ||
* @param e the exception to handle. | ||
* @param stageName the name of the stage where the exception occurred. | ||
* @param errorDetailsProvider the error details provider. | ||
* @param phase the phase of the stage where the exception occurred. | ||
* @return the wrapped stage exception. | ||
*/ | ||
public static WrappedStageException handleException(Exception e, String stageName, | ||
@Nullable ErrorDetailsProvider errorDetailsProvider, @Nullable ErrorPhase phase) { | ||
ProgramFailureException exception = null; | ||
|
||
if (!(e instanceof ProgramFailureException)) { | ||
exception = errorDetailsProvider == null ? null : | ||
errorDetailsProvider.getExceptionDetails(e, phase); | ||
} | ||
return new WrappedStageException(exception == null ? e : exception, stageName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.