From 41286b7545f8fc6a4a8c9782b169afd62a73e9c1 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 26 Jul 2018 15:17:55 -0700 Subject: [PATCH] [sql lab] extract Hive error messages (#5495) * [sql lab] extract Hive error messages So pyhive returns an exception object with a stringified thrift error object. This PR uses a regex to extract the errorMessage portion of that string. * Unit test --- superset/db_engine_specs.py | 8 ++++---- tests/db_engine_specs_test.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index cc1345e371a88..5e5a30414ad60 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -1051,10 +1051,10 @@ def adjust_database_uri(cls, uri, selected_schema=None): @classmethod def extract_error_message(cls, e): - try: - msg = e.message.status.errorMessage - except Exception: - msg = str(e) + msg = str(e) + match = re.search('errorMessage="(.*)", ', msg) + if match: + msg = match.group(1) return msg @classmethod diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py index c85e23a26c023..287114ccd7a0f 100644 --- a/tests/db_engine_specs_test.py +++ b/tests/db_engine_specs_test.py @@ -4,6 +4,8 @@ from __future__ import print_function from __future__ import unicode_literals +from six import text_type + from superset.db_engine_specs import ( BaseEngineSpec, HiveEngineSpec, MssqlEngineSpec, MySQLEngineSpec, PrestoEngineSpec, @@ -84,6 +86,23 @@ def test_job_2_launched_stage_2_stages_progress(self): """.split('\n') # noqa ignore: E501 self.assertEquals(60, HiveEngineSpec.progress(log)) + def test_hive_error_msg(self): + msg = ( + '{...} errorMessage="Error while compiling statement: FAILED: ' + 'SemanticException [Error 10001]: Line 4' + ':5 Table not found \'fact_ridesfdslakj\'", statusCode=3, ' + 'sqlState=\'42S02\', errorCode=10001)){...}') + self.assertEquals(( + 'Error while compiling statement: FAILED: ' + 'SemanticException [Error 10001]: Line 4:5 ' + "Table not found 'fact_ridesfdslakj'"), + HiveEngineSpec.extract_error_message(Exception(msg))) + + e = Exception("Some string that doesn't match the regex") + self.assertEquals( + text_type(e), + HiveEngineSpec.extract_error_message(e)) + def get_generic_database(self): return Database(sqlalchemy_uri='mysql://localhost')