From 0293f110be13e7fb71c5f9590bc73ed8d0c630aa Mon Sep 17 00:00:00 2001 From: AMit-Cloudsufi Date: Tue, 11 Feb 2025 14:49:22 +0000 Subject: [PATCH] update --- .../main/java/io/cdap/wrangler/Wrangler.java | 12 ++++-- .../io/cdap/wrangler/WranglerErrorUtil.java | 41 ++++++++----------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/wrangler-transform/src/main/java/io/cdap/wrangler/Wrangler.java b/wrangler-transform/src/main/java/io/cdap/wrangler/Wrangler.java index 338fd42f8..d4af8590e 100644 --- a/wrangler-transform/src/main/java/io/cdap/wrangler/Wrangler.java +++ b/wrangler-transform/src/main/java/io/cdap/wrangler/Wrangler.java @@ -24,7 +24,9 @@ import io.cdap.cdap.api.annotation.Plugin; import io.cdap.cdap.api.data.format.StructuredRecord; import io.cdap.cdap.api.data.schema.Schema; +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.metrics.Metrics; import io.cdap.cdap.api.plugin.PluginConfig; import io.cdap.cdap.api.plugin.PluginProperties; @@ -468,8 +470,9 @@ && checkPreconditionNotEmpty(false)) { && onErrorStrategy.equalsIgnoreCase(ON_ERROR_FAIL_PIPELINE)) { String errorReason = String.format("Errors in Wrangler Transformation - %s", errorMessages); - throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(null, errorReason, - errorReason, ErrorType.UNKNOWN); + throw ErrorUtils.getProgramFailureException( + new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorReason, + ErrorType.UNKNOWN, false, null); } } } catch (Exception e) { @@ -620,8 +623,9 @@ && checkPreconditionNotEmpty(true)) { if (!Feature.WRANGLER_PRECONDITION_SQL.isEnabled(relationalTranformContext)) { String errorReason = "SQL Precondition feature is not available"; - throw WranglerErrorUtil.getProgramFailureExceptionDetailsFromChain(null, errorReason, - errorReason, ErrorType.SYSTEM); + throw ErrorUtils.getProgramFailureException( + new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorReason, + ErrorType.SYSTEM, false, null); } Optional> expressionFactory = getExpressionFactory(relationalTranformContext); diff --git a/wrangler-transform/src/main/java/io/cdap/wrangler/WranglerErrorUtil.java b/wrangler-transform/src/main/java/io/cdap/wrangler/WranglerErrorUtil.java index 4f4c8f21f..a80309f85 100644 --- a/wrangler-transform/src/main/java/io/cdap/wrangler/WranglerErrorUtil.java +++ b/wrangler-transform/src/main/java/io/cdap/wrangler/WranglerErrorUtil.java @@ -75,35 +75,30 @@ private WranglerErrorUtil() { */ public static ProgramFailureException getProgramFailureExceptionDetailsFromChain(Throwable e, String errorReason, String errorMessage, ErrorType errorType) { - if (e != null) { - List 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); - } + List causalChain = Throwables.getCausalChain(e); + Throwable nonTerminalException = null; + for (Throwable t : causalChain) { + if (t instanceof ProgramFailureException) { + return null; // Avoid multiple wrap } - - if (nonTerminalException != null) { - return getProgramFailureException(nonTerminalException, errorReason, - NON_TERMINAL_EXCEPTIONS.get(nonTerminalException.getClass().getName())); + 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); } + } - return ErrorUtils.getProgramFailureException( - new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorMessage, - errorType, false, e); + if (nonTerminalException != null) { + return getProgramFailureException(nonTerminalException, errorReason, + NON_TERMINAL_EXCEPTIONS.get(nonTerminalException.getClass().getName())); } + return ErrorUtils.getProgramFailureException( new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), errorReason, errorMessage, - errorType, false, null); + errorType, false, e); } /**