From eadff5f41e2478b84dc198b4c5ed05ac7bb7f353 Mon Sep 17 00:00:00 2001 From: AAfghahi <48933336+AAfghahi@users.noreply.github.com> Date: Thu, 15 Apr 2021 11:02:47 -0400 Subject: [PATCH] feat: invalid DB name error messages (MySQL/Postgres/Redshift) (#14146) * initial DB custom errors for mysql * added redshift and postgres --- .../pages/docs/Miscellaneous/issue_codes.mdx | 12 +++++- .../src/components/ErrorMessage/types.ts | 2 + superset/db_engine_specs/mysql.py | 10 +++++ superset/db_engine_specs/postgres.py | 10 +++++ superset/db_engine_specs/redshift.py | 10 +++++ superset/errors.py | 10 +++++ tests/db_engine_specs/mysql_tests.py | 36 +++++++++++++++--- tests/db_engine_specs/postgres_tests.py | 35 +++++++++++++++-- tests/db_engine_specs/redshift_tests.py | 38 ++++++++++++++++--- 9 files changed, 147 insertions(+), 16 deletions(-) diff --git a/docs/src/pages/docs/Miscellaneous/issue_codes.mdx b/docs/src/pages/docs/Miscellaneous/issue_codes.mdx index baf7422b9..36e4df214 100644 --- a/docs/src/pages/docs/Miscellaneous/issue_codes.mdx +++ b/docs/src/pages/docs/Miscellaneous/issue_codes.mdx @@ -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. diff --git a/superset-frontend/src/components/ErrorMessage/types.ts b/superset-frontend/src/components/ErrorMessage/types.ts index 00d21226a..a85c2a129 100644 --- a/superset-frontend/src/components/ErrorMessage/types.ts +++ b/superset-frontend/src/components/ErrorMessage/types.ts @@ -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', diff --git a/superset/db_engine_specs/mysql.py b/superset/db_engine_specs/mysql.py index 28a0a6a7f..049ff1679 100644 --- a/superset/db_engine_specs/mysql.py +++ b/superset/db_engine_specs/mysql.py @@ -50,6 +50,9 @@ TEST_CONNECTION_INVALID_HOSTNAME_REGEX = re.compile( TEST_CONNECTION_HOST_DOWN_REGEX = re.compile( "Can't connect to MySQL server on '(?P.*?)'." ) +TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile( + "Unknown database '(?P.*?)'." +) class MySQLEngineSpec(BaseEngineSpec): @@ -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 diff --git a/superset/db_engine_specs/postgres.py b/superset/db_engine_specs/postgres.py index 59effff0c..9de126437 100644 --- a/superset/db_engine_specs/postgres.py +++ b/superset/db_engine_specs/postgres.py @@ -76,6 +76,9 @@ TEST_CONNECTION_HOST_DOWN_REGEX = re.compile( r'host "(?P.*?)" (\(.*?\) )?and accepting\s+TCP/IP ' r"connections on port (?P.*?)\?" ) +TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile( + 'database "(?P.*?)" does not exist' +) class PostgresBaseEngineSpec(BaseEngineSpec): @@ -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 diff --git a/superset/db_engine_specs/redshift.py b/superset/db_engine_specs/redshift.py index 90afc27dc..113cadf98 100644 --- a/superset/db_engine_specs/redshift.py +++ b/superset/db_engine_specs/redshift.py @@ -39,6 +39,9 @@ TEST_CONNECTION_HOST_DOWN_REGEX = re.compile( r'host "(?P.*?)" (\(.*?\) )?and accepting\s+TCP/IP ' r"connections on port (?P.*?)\?" ) +TEST_CONNECTION_UNKNOWN_DATABASE_REGEX = re.compile( + 'database "(?P.*?)" does not exist' +) class RedshiftEngineSpec(PostgresBaseEngineSpec): @@ -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 diff --git a/superset/errors.py b/superset/errors.py index c91e374e0..dc6008361 100644 --- a/superset/errors.py +++ b/superset/errors.py @@ -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" @@ -180,6 +181,15 @@ ERROR_TYPES_TO_ISSUE_CODES_MAPPING = { "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." + ), + } + ], } diff --git a/tests/db_engine_specs/mysql_tests.py b/tests/db_engine_specs/mysql_tests.py index 3c71dc8ac..f619bdd06 100644 --- a/tests/db_engine_specs/mysql_tests.py +++ b/tests/db_engine_specs/mysql_tests.py @@ -122,7 +122,8 @@ class TestMySQLEngineSpecsDbEngineSpec(TestDbEngineSpec): "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.", } ], }, @@ -141,7 +142,8 @@ class TestMySQLEngineSpecsDbEngineSpec(TestDbEngineSpec): "issue_codes": [ { "code": 1007, - "message": "Issue 1007 - The hostname provided can't be resolved.", + "message": "Issue 1007 - The hostname" + " provided can't be resolved.", } ], }, @@ -153,14 +155,16 @@ class TestMySQLEngineSpecsDbEngineSpec(TestDbEngineSpec): 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.", } ], }, @@ -179,7 +183,29 @@ class TestMySQLEngineSpecsDbEngineSpec(TestDbEngineSpec): "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.", } ], }, diff --git a/tests/db_engine_specs/postgres_tests.py b/tests/db_engine_specs/postgres_tests.py index 867faa126..164c1211d 100644 --- a/tests/db_engine_specs/postgres_tests.py +++ b/tests/db_engine_specs/postgres_tests.py @@ -238,7 +238,10 @@ class TestPostgresDbEngineSpec(TestDbEngineSpec): ) ] - 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( @@ -250,7 +253,8 @@ class TestPostgresDbEngineSpec(TestDbEngineSpec): "issue_codes": [ { "code": 1007, - "message": "Issue 1007 - The hostname provided can't be resolved.", + "message": "Issue 1007 - The hostname provided " + "can't be resolved.", } ], }, @@ -303,7 +307,8 @@ psql: error: could not connect to server: Operation timed out "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.", } ], }, @@ -332,7 +337,8 @@ psql: error: could not connect to server: Operation timed out "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.", } ], }, @@ -360,3 +366,24 @@ psql: error: could not connect to server: Operation timed out }, ) ] + + 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.", + } + ], + }, + ) + ] diff --git a/tests/db_engine_specs/redshift_tests.py b/tests/db_engine_specs/redshift_tests.py index cacb90a8e..fa0353d1a 100644 --- a/tests/db_engine_specs/redshift_tests.py +++ b/tests/db_engine_specs/redshift_tests.py @@ -39,14 +39,18 @@ class TestRedshiftDbEngineSpec(TestDbEngineSpec): "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( @@ -58,7 +62,8 @@ class TestRedshiftDbEngineSpec(TestDbEngineSpec): "issue_codes": [ { "code": 1007, - "message": "Issue 1007 - The hostname provided can't be resolved.", + "message": "Issue 1007 - The hostname provided " + "can't be resolved.", } ], }, @@ -110,7 +115,8 @@ psql: error: could not connect to server: Operation timed out "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.", } ], }, @@ -139,7 +145,29 @@ psql: error: could not connect to server: Operation timed out "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.", } ], },