AAfghahi commented on a change in pull request #14089:
URL: https://github.com/apache/superset/pull/14089#discussion_r611989726



##########
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:
       `psql: error: could not connect to server: Operation timed out
           Is the server running on host "93.184.216.34" and accepting
           TCP/IP connections on port 12345?
               """
           )
           result = PostgresEngineSpec.extract_errors(Exception(msg))
           assert result == [
               SupersetError(
                   error_type=SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR,
                   message=(
                       "The host 93.184.216.34 might be down, "
                       "and can't be reached on port 12345"
                   ),
                   level=ErrorLevel.ERROR,
                   extra={"engine_name": "PostgreSQL"},
               )
           ]`
   
   Like this one? From your PR 




-- 
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]

Reply via email to