Skip to content

Commit

Permalink
feat: invalid DB name error messages (MySQL/Postgres/Redshift) (apach…
Browse files Browse the repository at this point in the history
…e#14146)

* initial DB custom errors for mysql

* added redshift and postgres
  • Loading branch information
AAfghahi authored Apr 15, 2021
1 parent 8279697 commit 42399b2
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 16 deletions.
12 changes: 10 additions & 2 deletions docs/src/pages/docs/Miscellaneous/issue_codes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,13 @@ password is typed correctly.
Either the username or the password used are incorrect.
```

Either the username provided does not exist or the password was written
incorrectly. Please check that the username and password were typed correctly.
Either the username provided does not exist or the password was written incorrectly. Please
check that the username and password were typed correctly.

## Issue 1015

```
Either the database is spelled incorrectly or does not exist.
```

Either the database was written incorrectly or it does not exist. Check that it was typed correctly.
2 changes: 2 additions & 0 deletions superset-frontend/src/components/ErrorMessage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const ErrorTypeEnum = {
TEST_CONNECTION_PORT_CLOSED_ERROR: 'TEST_CONNECTION_PORT_CLOSED_ERROR',
TEST_CONNECTION_HOST_DOWN_ERROR: 'TEST_CONNECTION_HOST_DOWN_ERROR',
TEST_CONNECTION_ACCESS_DENIED_ERROR: 'TEST_CONNECTION_ACCESS_DENIED_ERROR',
TEST_CONNECTION_UNKNOWN_DATABASE_ERROR:
'TEST_CONNECTION_UNKNOWN_DATABASE_ERROR',

// Viz errors
VIZ_GET_DF_ERROR: 'VIZ_GET_DF_ERROR',
Expand Down
10 changes: 10 additions & 0 deletions superset/db_engine_specs/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
TEST_CONNECTION_HOST_DOWN_REGEX = re.compile(
"Can't connect to MySQL server on '(?P<hostname>.*?)'."
)
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile(
"Unknown database '(?P<database>.*?)'."
)


class MySQLEngineSpec(BaseEngineSpec):
Expand Down Expand Up @@ -119,6 +122,13 @@ class MySQLEngineSpec(BaseEngineSpec):
__('The host "%(hostname)s" might be down and can\'t be reached.'),
SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR,
),
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX: (
__(
'We were unable to connect to your database named "%(database)s". '
"Please verify your database name and try again."
),
SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR,
),
}

@classmethod
Expand Down
10 changes: 10 additions & 0 deletions superset/db_engine_specs/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ class FixedOffsetTimezone(_FixedOffset):
r'host "(?P<hostname>.*?)" (\(.*?\) )?and accepting\s+TCP/IP '
r"connections on port (?P<port>.*?)\?"
)
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile(
'database "(?P<database>.*?)" does not exist'
)


class PostgresBaseEngineSpec(BaseEngineSpec):
Expand Down Expand Up @@ -120,6 +123,13 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
),
SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR,
),
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX: (
__(
'We were unable to connect to your database named "%(database)s".'
" Please verify your database name and try again."
),
SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR,
),
}

@classmethod
Expand Down
10 changes: 10 additions & 0 deletions superset/db_engine_specs/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
r'host "(?P<hostname>.*?)" (\(.*?\) )?and accepting\s+TCP/IP '
r"connections on port (?P<port>.*?)\?"
)
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile(
'database "(?P<database>.*?)" does not exist'
)


class RedshiftEngineSpec(PostgresBaseEngineSpec):
Expand Down Expand Up @@ -66,6 +69,13 @@ class RedshiftEngineSpec(PostgresBaseEngineSpec):
),
SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR,
),
TEST_CONNECTION_UNKNOWN_DATABASE_REGEX: (
__(
'We were unable to connect to your database named "%(database)s".'
" Please verify your database name and try again."
),
SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR,
),
}

@staticmethod
Expand Down
10 changes: 10 additions & 0 deletions superset/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SupersetErrorType(str, Enum):
TEST_CONNECTION_PORT_CLOSED_ERROR = "TEST_CONNECTION_PORT_CLOSED_ERROR"
TEST_CONNECTION_HOST_DOWN_ERROR = "TEST_CONNECTION_HOST_DOWN_ERROR"
TEST_CONNECTION_ACCESS_DENIED_ERROR = "TEST_CONNECTION_ACCESS_DENIED_ERROR"
TEST_CONNECTION_UNKNOWN_DATABASE_ERROR = "TEST_CONNECTION_UNKNOWN_DATABASE_ERROR"

# Viz errors
VIZ_GET_DF_ERROR = "VIZ_GET_DF_ERROR"
Expand Down Expand Up @@ -180,6 +181,15 @@ class SupersetErrorType(str, Enum):
"message": _("Issue 1014 - Either the username or the password is wrong."),
}
],
SupersetErrorType.TEST_CONNECTION_UNKNOWN_DATABASE_ERROR: [
{
"code": 1015,
"message": _(
"Issue 1015 - Either the database is "
"spelled incorrectly or does not exist."
),
}
],
}


Expand Down
36 changes: 31 additions & 5 deletions tests/db_engine_specs/mysql_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1014,
"message": "Issue 1014 - Either the username or the password is wrong.",
"message": "Issue 1014 - Either the"
" username or the password is wrong.",
}
],
},
Expand All @@ -141,7 +142,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname"
" provided can't be resolved.",
}
],
},
Expand All @@ -153,14 +155,16 @@ def test_extract_errors(self):
assert result == [
SupersetError(
error_type=SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR,
message='The host "badconnection.com" might be down and can\'t be reached.',
message='The host "badconnection.com" might be '
"down and can't be reached.",
level=ErrorLevel.ERROR,
extra={
"engine_name": "MySQL",
"issue_codes": [
{
"code": 1007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname provided"
" can't be resolved.",
}
],
},
Expand All @@ -179,7 +183,29 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 10007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname provided "
"can't be resolved.",
}
],
},
)
]

msg = "mysql: Unknown database 'badDB'."
result = MySQLEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
error_type=SupersetErrorType.TEST_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.",
}
],
},
Expand Down
35 changes: 31 additions & 4 deletions tests/db_engine_specs/postgres_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ def test_extract_errors(self):
)
]

msg = 'psql: error: could not translate host name "locahost" to address: nodename nor servname provided, or not known'
msg = (
'psql: error: could not translate host name "locahost" to address: '
"nodename nor servname provided, or not known"
)
result = PostgresEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
Expand All @@ -250,7 +253,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname provided "
"can't be resolved.",
}
],
},
Expand Down Expand Up @@ -303,7 +307,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1009,
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
"message": "Issue 1009 - The host might be down, "
"and can't be reached on the provided port.",
}
],
},
Expand Down Expand Up @@ -332,7 +337,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1009,
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
"message": "Issue 1009 - The host might be down, "
"and can't be reached on the provided port.",
}
],
},
Expand Down Expand Up @@ -360,3 +366,24 @@ def test_extract_errors(self):
},
)
]

msg = 'database "badDB" does not exist'
result = PostgresEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
error_type=SupersetErrorType.TEST_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.",
}
],
},
)
]
38 changes: 33 additions & 5 deletions tests/db_engine_specs/redshift_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1014,
"message": "Issue 1014 - Either the username or the password is wrong",
"message": "Issue 1014 - Either the username or "
"the password is wrong",
}
],
},
)
]

msg = 'redshift: error: could not translate host name "badhost" to address: nodename nor servname provided, or not known'
msg = (
'redshift: error: could not translate host name "badhost" '
"to address: nodename nor servname provided, or not known"
)
result = RedshiftEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
Expand All @@ -58,7 +62,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1007,
"message": "Issue 1007 - The hostname provided can't be resolved.",
"message": "Issue 1007 - The hostname provided "
"can't be resolved.",
}
],
},
Expand Down Expand Up @@ -110,7 +115,8 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1009,
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
"message": "Issue 1009 - The host might be down, "
"and can't be reached on the provided port.",
}
],
},
Expand Down Expand Up @@ -139,7 +145,29 @@ def test_extract_errors(self):
"issue_codes": [
{
"code": 1009,
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.",
"message": "Issue 1009 - The host might be down, "
"and can't be reached on the provided port.",
}
],
},
)
]

msg = 'database "badDB" does not exist'
result = RedshiftEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
error_type=SupersetErrorType.TEST_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": "Amazon Redshift",
"issue_codes": [
{
"code": 10015,
"message": "Issue 1015 - Either the database is "
"spelled incorrectly or does not exist.",
}
],
},
Expand Down

0 comments on commit 42399b2

Please sign in to comment.