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



##########
File path: tests/db_engine_specs/presto_tests.py
##########
@@ -829,6 +830,193 @@ def test_extract_error_message_general_exception(self):
         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,

Review comment:
       I think this one needs to be reformatted to reflect the newer language? 
Unless we merge this one in first, then merge the mssql changes. 




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