betodealmeida commented on a change in pull request #14089:
URL: https://github.com/apache/superset/pull/14089#discussion_r611997737
##########
File path: superset/db_engine_specs/mysql.py
##########
@@ -93,6 +104,21 @@ class MySQLEngineSpec(BaseEngineSpec):
type_code_map: Dict[int, str] = {} # loaded from get_datatype only if
needed
+ custom_errors = {
+ INVALID_ACCESS_REGEX: (
+ __('Either the username "%(username)s" or the password is
incorrect.'),
+ SupersetErrorType.TEST_CONNECTION_ACCESS_DENIED_ERROR,
+ ),
+ INVALID_HOSTNAME_REGEX: (
+ __('Unknown MySQL server host "%(hostname)s"'),
+ SupersetErrorType.TEST_CONNECTION_INVALID_HOSTNAME_ERROR,
+ ),
+ CONNECTION_HOST_DOWN_REGEX: (
Review comment:
Same here, let's call this just `HOST_DOWN_REGEX`.
##########
File path: superset/db_engine_specs/mysql.py
##########
@@ -93,6 +104,21 @@ class MySQLEngineSpec(BaseEngineSpec):
type_code_map: Dict[int, str] = {} # loaded from get_datatype only if
needed
+ custom_errors = {
+ INVALID_ACCESS_REGEX: (
+ __('Either the username "%(username)s" or the password is
incorrect.'),
+ SupersetErrorType.TEST_CONNECTION_ACCESS_DENIED_ERROR,
+ ),
+ INVALID_HOSTNAME_REGEX: (
+ __('Unknown MySQL server host "%(hostname)s"'),
Review comment:
Period here as well.
##########
File path: superset/db_engine_specs/mysql.py
##########
@@ -93,6 +104,21 @@ class MySQLEngineSpec(BaseEngineSpec):
type_code_map: Dict[int, str] = {} # loaded from get_datatype only if
needed
+ custom_errors = {
+ INVALID_ACCESS_REGEX: (
+ __('Either the username "%(username)s" or the password is
incorrect.'),
+ SupersetErrorType.TEST_CONNECTION_ACCESS_DENIED_ERROR,
Review comment:
Let's rename the regex to `ACCESS_DENIED_REGEX`, to be consistent with
the other errors.
##########
File path: docs/src/pages/docs/Miscellaneous/issue_codes.mdx
##########
@@ -144,8 +144,8 @@ that the username is typed correctly and exists in the
database.
## Issue 1013
```
-The password provided when connecting to a database is not valid.
+Either the username or the password used are incorrect.
```
-The user provided a password that is incorrect. Please check that the
-password is typed correctly.
+Either the username provided does not exist or the password was written
incorrectly. Please
+check that the username and were typed correctly.
Review comment:
I merged issue 1013 already, so your PR is trying to replace it. You
need to use 1014 now.
##########
File path: tests/db_engine_specs/mysql_tests.py
##########
@@ -104,3 +105,64 @@ def test_extract_error_message(self):
exception = OperationalError(123, message)
extracted_message = MySQLEngineSpec._extract_error_message(exception)
assert extracted_message == message
+
+ def test_extract_errors(self):
+ """
+ Test that custom error messages are extracted correctly.
+ """
+ msg = "mysql: Access denied for user 'test'@'testuser.com' "
+ result = MySQLEngineSpec.extract_errors(Exception(msg))
+ assert result == [
+ SupersetError(
+
error_type=SupersetErrorType.TEST_CONNECTION_ACCESS_DENIED_ERROR,
+ message='Either the username "test" or password is incorrect',
+ level=ErrorLevel.ERROR,
+ extra={
+ "engine_name": "MySQL",
+ "issue_codes": [
+ {
+ "code": 1013,
+ "message": "Issue 1013 - Either the username or
the password is wrong.",
+ }
+ ],
+ },
+ )
+ ]
+
+ msg = "mysql: Unknown MySQL server host 'badhostname.com' "
+ result = MySQLEngineSpec.extract_errors(Exception(msg))
+ assert result == [
+ SupersetError(
+
error_type=SupersetErrorType.TEST_CONNECTION_INVALID_HOSTNAME_ERROR,
+ message='Unknown MySQL server host "badhostname.com"',
+ level=ErrorLevel.ERROR,
+ extra={
+ "engine_name": "MySQL",
+ "issue_codes": [
+ {
+ "code": 1007,
+ "message": "Issue 1007 - The hostname provided
can't be resolved.",
+ }
+ ],
+ },
+ )
+ ]
+
+ msg = "mysql: Can't connect to MySQL server on 'badconnection.com'"
Review comment:
For Postgres I tested with both a hostname and an IP, and made sure the
regex captured both.
##########
File path: superset/errors.py
##########
@@ -164,14 +165,13 @@ class SupersetErrorType(str, Enum):
),
},
],
- SupersetErrorType.TEST_CONNECTION_INVALID_PASSWORD_ERROR: [
+ SupersetErrorType.TEST_CONNECTION_ACCESS_DENIED_ERROR: [
Review comment:
Same thing, your PR is trying to override an existing error. You need to
change this to 1014 and add it below.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]