Skip to content

Commit

Permalink
parameter update
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-CloudSufi committed Feb 11, 2025
1 parent 9836b91 commit 1ca3c0f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
22 changes: 11 additions & 11 deletions wrangler-transform/src/main/java/io/cdap/wrangler/Wrangler.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void prepareRun(StageSubmitterContext context) throws Exception {
directives = recipe.parse();
} catch (Exception e) {
String errorReason = "Unable to parse recipe and extract all instances of directives.";
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, null, errorReason,
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorReason, null,
ErrorType.USER);
}
emitDirectiveMetrics(directives, context.getMetrics());
Expand Down Expand Up @@ -369,8 +369,8 @@ public void initialize(TransformContext context) throws Exception {
String errorMessage = String.format(
"Format of output schema specified is invalid. Please check the format. %s: %s",
e.getClass().getName(), e.getMessage());
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorMessage,
errorReason, ErrorType.USER);
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorReason,
errorMessage, ErrorType.USER);
}

// Check if jexl pre-condition is not null or empty and if so compile expression.
Expand All @@ -381,7 +381,7 @@ && checkPreconditionNotEmpty(false)) {
condition = new Precondition(config.getPreconditionJEXL());
} catch (Exception e) {
String errorReason = "Failed to evaluate precondition due to an invalid JEXL expression.";
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, null, errorReason,
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorReason, null,
ErrorType.USER);
}
}
Expand All @@ -395,8 +395,8 @@ && checkPreconditionNotEmpty(false)) {
String errorMessage = String.format(
"Error compiling the recipe and executing directives. " + "%s: %s",
e.getClass().getName(), e.getMessage());
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorMessage,
errorReason, ErrorType.USER);
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorReason,
errorMessage, ErrorType.USER);
}

String defaultStrategy = context.getArguments().get(ERROR_STRATEGY_DEFAULT);
Expand Down Expand Up @@ -492,8 +492,8 @@ && checkPreconditionNotEmpty(false)) {
+ "transformation or schema mismatch.";
String errorMessage = String.format("Pipeline failed at stage:%s, %s: %s",
getContext().getStageName(), e.getClass().getName(), e.getMessage());
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorMessage,
errorReason, ErrorType.UNKNOWN);
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorReason,
errorMessage, ErrorType.UNKNOWN);
}
// If it's 'skip-on-error' we continue processing and don't emit any error records.
return;
Expand Down Expand Up @@ -595,7 +595,7 @@ private RecipeParser getRecipeParser(StageContext context) {
registry.reload(context.getNamespace());
} catch (Exception e) {
String errorReason = "Unable to load directive from the artifacts.";
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, null, errorReason,
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorReason, null,
ErrorType.USER);
}

Expand All @@ -608,7 +608,7 @@ private RecipeParser getRecipeParser(StageContext context) {
return new GrammarBasedParser(context.getNamespace(), new MigrateToV2(directives).migrate(), registry);
} catch (Exception e) {
String errorReason = "Unable to parse the directives.";
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, null, errorReason,
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorReason, null,
ErrorType.USER);
}
}
Expand Down Expand Up @@ -656,7 +656,7 @@ private void emitDirectiveMetrics(List<Directive> directives, Metrics metrics) {
} catch (Exception e) {
String errorReason = String.format("Unable to load directive %s",
directive.define().getDirectiveName());
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, null, errorReason,
throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(e, errorReason, null,
ErrorType.USER);
}
List<EntityCountMetric> countMetrics = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,42 +68,42 @@ private WranglerErrorUtil() {
* returned.
*
* @param e the Throwable to analyze
* @param errorReason the error reason to tell the cause of error
* @param errorMessage default error message if no terminal exception is found
* @param errorType the error type to categorize the failure
* @return a ProgramFailureException with specific or generic error details
*/
public static ProgramFailureException getProgramFailureExceptionDetailsFromChain(Throwable e,
String errorMessage, String errorReason, ErrorType errorType) {
if (e == null) {
return ErrorUtils.getProgramFailureException(
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorMessage,
errorType, false, null);
}

List<Throwable> causalChain = Throwables.getCausalChain(e);
Throwable nonTerminalException = null;
for (Throwable t : causalChain) {
if (t instanceof ProgramFailureException) {
return null; // Avoid multiple wrap
}
if (NON_TERMINAL_EXCEPTIONS.containsKey(t.getClass().getName())) {
nonTerminalException = t; // Store non-terminal exception as fallback
continue;
String errorReason, String errorMessage, ErrorType errorType) {
if (e != null) {
List<Throwable> causalChain = Throwables.getCausalChain(e);
Throwable nonTerminalException = null;
for (Throwable t : causalChain) {
if (t instanceof ProgramFailureException) {
return null; // Avoid multiple wrap
}
if (NON_TERMINAL_EXCEPTIONS.containsKey(t.getClass().getName())) {
nonTerminalException = t; // Store non-terminal exception as fallback
continue;
}
String errorSubCategory = TERMINAL_EXCEPTIONS.get(t.getClass().getName());
if (errorSubCategory != null) {
return getProgramFailureException(t, errorReason, errorSubCategory);
}
}
String errorSubCategory = TERMINAL_EXCEPTIONS.get(t.getClass().getName());
if (errorSubCategory != null) {
return getProgramFailureException(t, errorSubCategory, errorReason);

if (nonTerminalException != null) {
return getProgramFailureException(nonTerminalException, errorReason,
NON_TERMINAL_EXCEPTIONS.get(nonTerminalException.getClass().getName()));
}
}

if (nonTerminalException != null) {
return getProgramFailureException(nonTerminalException,
NON_TERMINAL_EXCEPTIONS.get(nonTerminalException.getClass().getName()), errorReason);
return ErrorUtils.getProgramFailureException(
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorMessage,
errorType, false, e);
}

return ErrorUtils.getProgramFailureException(
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorMessage,
errorType, false, e);
errorType, false, null);
}

/**
Expand All @@ -114,7 +114,7 @@ public static ProgramFailureException getProgramFailureExceptionDetailsFromChain
* @return a new ProgramFailureException with the extracted details
*/
private static ProgramFailureException getProgramFailureException(Throwable exception,
String errorSubCategory, String errorReason) {
String errorReason, String errorSubCategory) {
String errorMessage = exception.getMessage();
return ErrorUtils.getProgramFailureException(
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN, errorSubCategory), errorReason,
Expand Down

0 comments on commit 1ca3c0f

Please sign in to comment.