-
Notifications
You must be signed in to change notification settings - Fork 34
[PLUGIN-1830] Add PostgresErrorDetailsProvider #527
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
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
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
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
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
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
96 changes: 96 additions & 0 deletions
96
postgresql-plugin/src/main/java/io/cdap/plugin/postgres/PostgresErrorDetailsProvider.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,96 @@ | ||
| /* | ||
| * Copyright © 2024 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.plugin.postgres; | ||
|
|
||
| import com.google.common.base.Strings; | ||
| import io.cdap.cdap.api.exception.ErrorCategory; | ||
| import io.cdap.cdap.api.exception.ErrorType; | ||
| import io.cdap.plugin.db.DBErrorDetailsProvider; | ||
| import io.cdap.plugin.util.DBUtils; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * A custom ErrorDetailsProvider for Postgres plugins. | ||
| */ | ||
| public class PostgresErrorDetailsProvider extends DBErrorDetailsProvider { | ||
| // https://www.postgresql.org/docs/current/errcodes-appendix.html | ||
| private static final Map<String, ErrorType> ERROR_CODE_TO_ERROR_TYPE; | ||
| private static final Map<String, ErrorCategory> ERROR_CODE_TO_ERROR_CATEGORY; | ||
| static { | ||
| ERROR_CODE_TO_ERROR_TYPE = new HashMap<>(); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("01", ErrorType.USER); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("02", ErrorType.USER); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("08", ErrorType.SYSTEM); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("0A", ErrorType.USER); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("22", ErrorType.USER); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("23", ErrorType.USER); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("28", ErrorType.USER); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("40", ErrorType.SYSTEM); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("42", ErrorType.USER); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("53", ErrorType.SYSTEM); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("54", ErrorType.SYSTEM); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("55", ErrorType.USER); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("57", ErrorType.SYSTEM); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("58", ErrorType.SYSTEM); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("P0", ErrorType.SYSTEM); | ||
| ERROR_CODE_TO_ERROR_TYPE.put("XX", ErrorType.SYSTEM); | ||
itsankit-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ErrorCategory.ErrorCategoryEnum plugin = ErrorCategory.ErrorCategoryEnum.PLUGIN; | ||
| ERROR_CODE_TO_ERROR_CATEGORY = new HashMap<>(); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("01", new ErrorCategory(plugin, "Warning")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("02", new ErrorCategory(plugin, "No Data")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("08", new ErrorCategory(plugin, "Postgres Server Connection Exception")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("0A", new ErrorCategory(plugin, "Postgres Server Feature Not Supported")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("22", new ErrorCategory(plugin, "Postgres Server Data Exception")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("23", new ErrorCategory(plugin, "Postgres Integrity Constraint Violation")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("28", new ErrorCategory(plugin, "Postgres Invalid Authorization Specification")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("40", new ErrorCategory(plugin, "Transaction Rollback")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("42", new ErrorCategory(plugin, "Syntax Error or Access Rule Violation")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("53", new ErrorCategory(plugin, "Postgres Server Insufficient Resources")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("54", new ErrorCategory(plugin, "Postgres Program Limit Exceeded")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("55", new ErrorCategory(plugin, "Object Not in Prerequisite State")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("57", new ErrorCategory(plugin, "Operator Intervention")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("58", new ErrorCategory(plugin, "Postgres Server System Error")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("P0", new ErrorCategory(plugin, "PL/pgSQL Error")); | ||
| ERROR_CODE_TO_ERROR_CATEGORY.put("XX", new ErrorCategory(plugin, "Postgres Server Internal Error")); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getExternalDocumentationLink() { | ||
| return DBUtils.POSTGRES_SUPPORTED_DOC_URL; | ||
| } | ||
|
|
||
| @Override | ||
| protected ErrorType getErrorTypeFromErrorCode(int errorCode, String sqlState) { | ||
| if (!Strings.isNullOrEmpty(sqlState) && sqlState.length() >= 2 && | ||
| ERROR_CODE_TO_ERROR_TYPE.containsKey(sqlState.substring(0, 2))) { | ||
| return ERROR_CODE_TO_ERROR_TYPE.get(sqlState.substring(0, 2)); | ||
| } | ||
| return ErrorType.UNKNOWN; | ||
| } | ||
|
|
||
| @Override | ||
| protected ErrorCategory getErrorCategoryFromSqlState(String sqlState) { | ||
| if (!Strings.isNullOrEmpty(sqlState) && sqlState.length() >= 2 && | ||
| ERROR_CODE_TO_ERROR_CATEGORY.containsKey(sqlState.substring(0, 2))) { | ||
| return ERROR_CODE_TO_ERROR_CATEGORY.get(sqlState.substring(0, 2)); | ||
| } | ||
| return new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN); | ||
| } | ||
| } | ||
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
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
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.