mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat: error messages for Presto connections (#14172)
* chore: rename connection errors * feat: error messages for Presto connections * Add unit tests * Update docs/src/pages/docs/Miscellaneous/issue_codes.mdx Co-authored-by: AAfghahi <48933336+AAfghahi@users.noreply.github.com> Co-authored-by: AAfghahi <48933336+AAfghahi@users.noreply.github.com>
This commit is contained in:
@@ -200,17 +200,15 @@ class TestMySQLEngineSpecsDbEngineSpec(TestDbEngineSpec):
|
||||
result = MySQLEngineSpec.extract_errors(Exception(msg))
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message='Unable to connect to database "badDB".',
|
||||
error_type=SupersetErrorType.CONNECTION_UNKNOWN_DATABASE_ERROR,
|
||||
message='We were unable to connect to your database named "badDB".'
|
||||
" Please verify your database name and try again.",
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "MySQL",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 10015,
|
||||
"message": "Issue 1015 - Either the database is "
|
||||
"spelled incorrectly or does not exist.",
|
||||
"code": 1015,
|
||||
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.",
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
@@ -371,17 +371,18 @@ psql: error: could not connect to server: Operation timed out
|
||||
result = PostgresEngineSpec.extract_errors(Exception(msg))
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message='Unable to connect to database "badDB".',
|
||||
error_type=SupersetErrorType.CONNECTION_UNKNOWN_DATABASE_ERROR,
|
||||
message='We were unable to connect to your database named "badDB".'
|
||||
" Please verify your database name and try again.",
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "PostgreSQL",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 10015,
|
||||
"message": "Issue 1015 - Either the database is "
|
||||
"spelled incorrectly or does not exist.",
|
||||
"code": 1015,
|
||||
"message": (
|
||||
"Issue 1015 - Either the database is spelled "
|
||||
"incorrectly or does not exist.",
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
@@ -23,6 +23,7 @@ from sqlalchemy.engine.result import RowProxy
|
||||
from sqlalchemy.sql import select
|
||||
|
||||
from superset.db_engine_specs.presto import PrestoEngineSpec
|
||||
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
|
||||
from superset.sql_parse import ParsedQuery
|
||||
from superset.utils.core import DatasourceName, GenericDataType
|
||||
from tests.db_engine_specs.base_tests import TestDbEngineSpec
|
||||
@@ -829,6 +830,193 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
|
||||
result = PrestoEngineSpec._extract_error_message(exception)
|
||||
assert result == "Err message"
|
||||
|
||||
def test_extract_errors(self):
|
||||
msg = "Generic Error"
|
||||
result = PrestoEngineSpec.extract_errors(Exception(msg))
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message="Generic Error",
|
||||
error_type=SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "Presto",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1002,
|
||||
"message": "Issue 1002 - The database returned an unexpected error.",
|
||||
}
|
||||
],
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
msg = "line 1:8: Column 'bogus' cannot be resolved"
|
||||
result = PrestoEngineSpec.extract_errors(Exception(msg))
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message='We can\'t seem to resolve the column "bogus" at line 1:8.',
|
||||
error_type=SupersetErrorType.COLUMN_DOES_NOT_EXIST_ERROR,
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "Presto",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1003,
|
||||
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
|
||||
},
|
||||
{
|
||||
"code": 1004,
|
||||
"message": "Issue 1004 - The column was deleted or renamed in the database.",
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
msg = "line 1:15: Table 'tpch.tiny.region2' does not exist"
|
||||
result = PrestoEngineSpec.extract_errors(Exception(msg))
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message="The table \"'tpch.tiny.region2'\" does not exist. A valid table must be used to run this query.",
|
||||
error_type=SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "Presto",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1003,
|
||||
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
|
||||
},
|
||||
{
|
||||
"code": 1005,
|
||||
"message": "Issue 1005 - The table was deleted or renamed in the database.",
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
msg = "line 1:15: Schema 'tin' does not exist"
|
||||
result = PrestoEngineSpec.extract_errors(Exception(msg))
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message='The schema "tin" does not exist. A valid schema must be used to run this query.',
|
||||
error_type=SupersetErrorType.SCHEMA_DOES_NOT_EXIST_ERROR,
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "Presto",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1003,
|
||||
"message": "Issue 1003 - There is a syntax error in the SQL query. Perhaps there was a misspelling or a typo.",
|
||||
},
|
||||
{
|
||||
"code": 1016,
|
||||
"message": "Issue 1005 - The schema was deleted or renamed in the database.",
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
msg = b"Access Denied: Invalid credentials"
|
||||
result = PrestoEngineSpec.extract_errors(Exception(msg), {"username": "alice"})
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message='Either the username "alice" or the password is incorrect.',
|
||||
error_type=SupersetErrorType.CONNECTION_ACCESS_DENIED_ERROR,
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "Presto",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1014,
|
||||
"message": "Issue 1014 - Either the username or the password is wrong.",
|
||||
}
|
||||
],
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
msg = "Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known"
|
||||
result = PrestoEngineSpec.extract_errors(
|
||||
Exception(msg), {"hostname": "badhost"}
|
||||
)
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message='The hostname "badhost" cannot be resolved.',
|
||||
error_type=SupersetErrorType.CONNECTION_INVALID_HOSTNAME_ERROR,
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "Presto",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1007,
|
||||
"message": "Issue 1007 - The hostname provided can't be resolved.",
|
||||
}
|
||||
],
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
msg = "Failed to establish a new connection: [Errno 60] Operation timed out"
|
||||
result = PrestoEngineSpec.extract_errors(
|
||||
Exception(msg), {"hostname": "badhost", "port": 12345}
|
||||
)
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message='The host "badhost" might be down, and can\'t be reached on port 12345.',
|
||||
error_type=SupersetErrorType.CONNECTION_HOST_DOWN_ERROR,
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "Presto",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1009,
|
||||
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
|
||||
}
|
||||
],
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
msg = "Failed to establish a new connection: [Errno 61] Connection refused"
|
||||
result = PrestoEngineSpec.extract_errors(
|
||||
Exception(msg), {"hostname": "badhost", "port": 12345}
|
||||
)
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message='Port 12345 on hostname "badhost" refused the connection.',
|
||||
error_type=SupersetErrorType.CONNECTION_PORT_CLOSED_ERROR,
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "Presto",
|
||||
"issue_codes": [
|
||||
{"code": 1008, "message": "Issue 1008 - The port is closed."}
|
||||
],
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
msg = "line 1:15: Catalog 'wrong' does not exist"
|
||||
result = PrestoEngineSpec.extract_errors(Exception(msg))
|
||||
assert result == [
|
||||
SupersetError(
|
||||
message='Unable to connect to catalog named "wrong".',
|
||||
error_type=SupersetErrorType.CONNECTION_UNKNOWN_DATABASE_ERROR,
|
||||
level=ErrorLevel.ERROR,
|
||||
extra={
|
||||
"engine_name": "Presto",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1015,
|
||||
"message": "Issue 1015 - Either the database is spelled incorrectly or does not exist.",
|
||||
}
|
||||
],
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def test_is_readonly():
|
||||
def is_readonly(sql: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user