-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error management for Wrangler Transform plugin
- Loading branch information
1 parent
0f6e1b4
commit 1613e69
Showing
3 changed files
with
178 additions
and
40 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
75 changes: 75 additions & 0 deletions
75
wrangler-transform/src/main/java/io/cdap/wrangler/WranglerUtil.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,75 @@ | ||
/* | ||
* Copyright © 2025 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.wrangler; | ||
|
||
import com.google.common.base.Throwables; | ||
import io.cdap.cdap.api.exception.ErrorCategory; | ||
import io.cdap.cdap.api.exception.ErrorType; | ||
import io.cdap.cdap.api.exception.ErrorUtils; | ||
import io.cdap.cdap.api.exception.ProgramFailureException; | ||
import io.cdap.wrangler.api.DirectiveLoadException; | ||
import io.cdap.wrangler.api.DirectiveParseException; | ||
import io.cdap.wrangler.api.RecipeException; | ||
import java.util.List; | ||
|
||
/** | ||
* Util file to handle exceptions caught in Wrangler plugin | ||
*/ | ||
public class WranglerUtil { | ||
|
||
private WranglerUtil() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
public static ProgramFailureException getProgramFailureExceptionDetailsFromChain(Throwable e, | ||
String errorMessage, ErrorType errorType, boolean dependency) { | ||
if (e != null) { | ||
List<Throwable> causalChain = Throwables.getCausalChain(e); | ||
for (Throwable t : causalChain) { | ||
if (t instanceof ProgramFailureException) { | ||
// Avoid double wrap | ||
return (ProgramFailureException) t; | ||
} | ||
if (t instanceof DirectiveLoadException || t instanceof DirectiveParseException | ||
|| t instanceof RecipeException || t instanceof PreconditionException) { | ||
return getProgramFailureException((Exception) t, errorType, dependency); | ||
} | ||
} | ||
} | ||
// If no predefined exception found in the causal chain, return generic program failure exception | ||
return ErrorUtils.getProgramFailureException( | ||
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorMessage, errorMessage, | ||
errorType, dependency, e); | ||
} | ||
|
||
/** | ||
* Get a ProgramFailureException with the given error information from {@link Exception}. | ||
* | ||
* @param exception The Exception to get the error information from. | ||
* @param errorType The ErrorType to get the error type information. | ||
* @param dependency The dependency to show if it depends on external source or not | ||
* @return A ProgramFailureException with the given error information. | ||
*/ | ||
private static ProgramFailureException getProgramFailureException(Exception exception, | ||
ErrorType errorType, boolean dependency) { | ||
String errorMessage = exception.getMessage(); | ||
return ErrorUtils.getProgramFailureException( | ||
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorMessage, errorMessage, | ||
errorType, dependency, exception); | ||
} | ||
|
||
} |