Add util function getProgramFailureExceptionFromSQLException#1954
Merged
psainics merged 1 commit intocdapio:developfrom Mar 27, 2025
Merged
Add util function getProgramFailureExceptionFromSQLException#1954psainics merged 1 commit intocdapio:developfrom
psainics merged 1 commit intocdapio:developfrom
Conversation
Comment on lines
+183
to
+200
| public static ProgramFailureException getProgramFailureExceptionFromSQLException(SQLException e) { | ||
| String errorMessage = String.format("SQL Exception occurred: [Message='%s', SQLState='%s', ErrorCode='%s'].", | ||
| e.getMessage(), e.getSQLState(), e.getErrorCode()); | ||
| String sqlState = e.getSQLState(); | ||
| int errorCode = e.getErrorCode(); | ||
| String errorMessageWithDetails = String.format( | ||
| "SQL Error occurred, sqlState: '%s', errorCode: '%s', errorMessage: %s", sqlState, errorCode, errorMessage); | ||
| if (!errorMessage.endsWith(".")) { | ||
| errorMessage = errorMessage + "."; | ||
| } | ||
| errorMessage = String.format("%s For more details, see %s", errorMessage, EXTERNAL_DOCUMENTATION_LINK); | ||
| return ErrorUtils.getProgramFailureException( | ||
| Strings.isNullOrEmpty(sqlState) ? new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN) | ||
| : getErrorCategoryFromSqlStateDefault(sqlState), errorMessage, errorMessageWithDetails, | ||
| getErrorTypeFromErrorCodeAndSqlStateDefault(errorCode, sqlState), true, ErrorCodeType.SQLSTATE, sqlState, | ||
| EXTERNAL_DOCUMENTATION_LINK, e); | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
we can modify the below function itself to take external_documentation_link as param.
Also errorContext can be nullable if null, we can fallback to the errorMessage proposed in this function.
Please do not introduce duplicate code.
Author
There was a problem hiding this comment.
Removing all the static methods, it was not helpfull.
This will be the new code
try {
executeQuery.run();
} catch (Exception e) {
if (e instanceof SQLException) {
DBErrorDetailsProvider dbe = new DBErrorDetailsProvider();
throw dbe.getProgramFailureException((SQLException) e, null);
}
FailureCollector collector = context.getFailureCollector();
collector.addFailure("Failed to execute query with message: " + e.getMessage(), null)
.withStacktrace(e.getStackTrace());
collector.getOrThrowException();
}Rename DEFAULT_EXTERNAL_DOCUMENTATION_LINK
itsankit-google
approved these changes
Mar 27, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adding a util function that can be used to getProgramFailureExceptionFromSQLException.
Ref: data-integrations/database-plugins#568 (comment)
This code snippet can be modified to
Test
Moving default implementation to static methods, making the function static may lead to overriding issue in other projects.