-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[PLUGIN-1856] Error management for Wrangler plugin #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
psainics
merged 1 commit into
data-integrations:develop
from
cloudsufi:wranglerTransformPlugin
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
118 changes: 118 additions & 0 deletions
118
wrangler-transform/src/main/java/io/cdap/wrangler/WranglerErrorUtil.java
This file contains hidden or 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,118 @@ | ||
/* | ||
* 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 com.google.common.collect.ImmutableMap; | ||
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.DirectiveExecutionException; | ||
import io.cdap.wrangler.api.DirectiveLoadException; | ||
import io.cdap.wrangler.api.DirectiveNotFoundException; | ||
import io.cdap.wrangler.api.DirectiveParseException; | ||
import io.cdap.wrangler.api.RecipeException; | ||
import io.cdap.wrangler.expression.ELException; | ||
import io.cdap.wrangler.utils.RecordConvertorException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Error util file to handle exceptions caught in Wrangler plugin | ||
*/ | ||
public final class WranglerErrorUtil { | ||
|
||
|
||
private static final Map<String, String> TERMINAL_EXCEPTIONS = ImmutableMap.<String, String>builder() | ||
.put(DirectiveParseException.class.getName(), "Parsing-Directive") | ||
.put(PreconditionException.class.getName(), "Precondition") | ||
.put(DirectiveExecutionException.class.getName(), "Executing-Directive") | ||
.put(DirectiveLoadException.class.getName(), "Loading-Directive") | ||
.put(DirectiveNotFoundException.class.getName(), "Directive-Not-Found") | ||
.put(RecordConvertorException.class.getName(), "Record-Conversion") | ||
.put(ELException.class.getName(), "ExpressionLanguage-Parsing").build(); | ||
|
||
private static final Map<String, String> NON_TERMINAL_EXCEPTIONS = ImmutableMap.<String, String>builder() | ||
.put(RecipeException.class.getName(), "Executing-Recipe").build(); | ||
|
||
/** | ||
* Private constructor to prevent instantiation of this utility class. | ||
* <p> | ||
* This class is designed to contain only static utility methods for handling exceptions and | ||
* should not be instantiated. Any attempt to create an instance of this class will result in an | ||
* {@link IllegalStateException}. | ||
*/ | ||
private WranglerErrorUtil() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
/** | ||
* Traverses the causal chain of the given Throwable to find specific exceptions. If a terminal | ||
* exception is found, it returns a corresponding ProgramFailureException. If a non-terminal | ||
* exception is found, it is stored as a fallback. Otherwise, a generic ProgramFailureException is | ||
* 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, | ||
itsankit-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String errorReason, String errorMessage, ErrorType errorType) { | ||
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); | ||
} | ||
} | ||
|
||
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, e); | ||
} | ||
|
||
/** | ||
* Constructs a ProgramFailureException using the provided exception details. | ||
* | ||
* @param exception the exception to wrap | ||
* @param errorSubCategory specific subcategory of the error | ||
* @return a new ProgramFailureException with the extracted details | ||
*/ | ||
private static ProgramFailureException getProgramFailureException(Throwable exception, | ||
String errorReason, String errorSubCategory) { | ||
String errorMessage = exception.getMessage(); | ||
return ErrorUtils.getProgramFailureException( | ||
new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN, errorSubCategory), errorReason, | ||
errorMessage, ErrorType.USER, false, exception); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.