-
Notifications
You must be signed in to change notification settings - Fork 15.8k
feat(db): custom database error messages #34674
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
Open
DamianPendrak
wants to merge
19
commits into
apache:master
Choose a base branch
from
DamianPendrak:custom-db-error-messages
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+695
−17
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7d8a314
Add custom database error messages
DamianPendrak 6440a4d
Add tests, documentation, and examples
DamianPendrak dcf51d8
Add frontend tests
DamianPendrak 1bd8ac8
Improve custom doc links validation; Add test for wrong doc links value
DamianPendrak 5e23fac
Fix console error caused by missing key in a list
DamianPendrak cee606a
Change the custom doc links key
DamianPendrak ae01a18
Fix eslint
DamianPendrak 4b5224a
Add db engine specific custom error messages
DamianPendrak e2ff5ee
Move the custom database errors to a separate config file
DamianPendrak 8d81954
Improve custom error config import safety and test coverage
DamianPendrak 272815f
Add test to improve coverage
DamianPendrak 51631d7
Refactor extract_errors tests to use a helper function for expected S…
DamianPendrak 32678a1
Add more basic regex as an example
DamianPendrak 8e6abc7
Improve CustomDocLink component
DamianPendrak 2e09656
Match errors with engine_name and engine; Don't replace original mess…
DamianPendrak 3a15db6
Add database_name parameter to extract_errors
DamianPendrak ddef424
Change custom error matching from engine to database name
DamianPendrak 6766f4e
Apply PR feedback
DamianPendrak ad1ee1a
Temporary custom errors for testing
DamianPendrak 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
39 changes: 39 additions & 0 deletions
39
superset-frontend/src/components/ErrorMessage/CustomDocLink.test.tsx
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,39 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import { CustomDocLink } from './CustomDocLink'; | ||
|
||
const mockedProps = { | ||
url: 'https://superset.apache.org/docs/', | ||
label: 'Superset Docs', | ||
}; | ||
|
||
test('should render the label', () => { | ||
render(<CustomDocLink {...mockedProps} />); | ||
expect(screen.getByText('Superset Docs')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the link with correct attributes', () => { | ||
render(<CustomDocLink {...mockedProps} />); | ||
const link = screen.getByRole('link'); | ||
expect(link).toHaveAttribute('href', mockedProps.url); | ||
expect(link).toHaveAttribute('target', '_blank'); | ||
expect(link).toHaveAttribute('rel', 'noopener noreferrer'); | ||
}); |
33 changes: 33 additions & 0 deletions
33
superset-frontend/src/components/ErrorMessage/CustomDocLink.tsx
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,33 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
import { Flex, Icons } from '@superset-ui/core/components'; | ||
|
||
export type CustomDocLinkProps = { | ||
url: string; | ||
label: string; | ||
}; | ||
|
||
export const CustomDocLink = ({ url, label }: CustomDocLinkProps) => ( | ||
<a href={url} target="_blank" rel="noopener noreferrer"> | ||
<Flex align="center" gap={4}> | ||
{label} <Icons.Full iconSize="m" /> | ||
</Flex> | ||
</a> | ||
); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you 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. | ||
|
||
import re | ||
from typing import Any | ||
|
||
from flask_babel import gettext as __ | ||
|
||
from superset.errors import SupersetErrorType | ||
|
||
# CUSTOM_DATABASE_ERRORS: Configure custom error messages for database exceptions. | ||
# Transform raw database errors into user-friendly messages with optional documentation | ||
# links using custom_doc_links. Set show_issue_info=False to hide default error codes. | ||
# Example: | ||
# CUSTOM_DATABASE_ERRORS = { | ||
# "database_name": { | ||
# re.compile('permission denied for view'): ( | ||
# __( | ||
# 'Permission denied' | ||
# ), | ||
# SupersetErrorType.GENERIC_DB_ENGINE_ERROR, | ||
# { | ||
# "custom_doc_links": [ | ||
# { | ||
# "url": "https://example.com/docs/1", | ||
# "label": "Check documentation" | ||
# }, | ||
# ], | ||
# "show_issue_info": False, | ||
# } | ||
# ) | ||
# }, | ||
# "examples": { | ||
# re.compile(r'message="(?P<message>[^"]*)"'): ( | ||
# __( | ||
# 'Unexpected error: "%(message)s"' | ||
# ), | ||
# SupersetErrorType.GENERIC_DB_ENGINE_ERROR, | ||
# {} | ||
# ) | ||
# } | ||
# } | ||
|
||
CUSTOM_DATABASE_ERRORS: dict[ | ||
str, dict[re.Pattern[str], tuple[str, SupersetErrorType, dict[str, Any]]] | ||
] = { | ||
"examples": { | ||
re.compile("no such table: a"): ( | ||
__("This is custom error message for a"), | ||
SupersetErrorType.GENERIC_DB_ENGINE_ERROR, | ||
{ | ||
"custom_doc_links": [ | ||
{ | ||
"url": "https://example.com/docs/1", | ||
"label": "Custom documentation link", | ||
}, | ||
], | ||
"show_issue_info": False, | ||
}, | ||
), | ||
re.compile("no such table: b"): ( | ||
__("This is custom error message for b"), | ||
SupersetErrorType.GENERIC_DB_ENGINE_ERROR, | ||
{ | ||
"show_issue_info": True, | ||
}, | ||
), | ||
} | ||
} |
Oops, something went wrong.
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.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.