Skip to content

Commit

Permalink
Better error handling for presto (#2161)
Browse files Browse the repository at this point in the history
* Better error handling for presto

* Move to db_engine_spec
  • Loading branch information
vera-liu authored Feb 17, 2017
1 parent f5e3d0c commit fc85034
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from collections import namedtuple, defaultdict
from flask_babel import lazy_gettext as _
from superset import utils

import inspect
import textwrap
import time
Expand Down Expand Up @@ -91,6 +93,11 @@ def handle_cursor(cls, cursor, query, session):
query object"""
pass

@classmethod
def extract_error_message(cls, e):
"""Extract error message for queries"""
return utils.error_msg_from_exception(e)

@classmethod
def sql_preprocessor(cls, sql):
"""If the SQL needs to be altered prior to running it
Expand Down Expand Up @@ -312,6 +319,19 @@ def handle_cursor(cls, cursor, query, session):
time.sleep(1)
polled = cursor.poll()

@classmethod
def extract_error_message(cls, e):
if hasattr(e, 'orig') \
and type(e.orig).__name__ == 'DatabaseError' \
and isinstance(e.orig[0], dict):
error_dict = e.orig[0]
e = '{} at {}: {}'.format(
error_dict['errorName'],
error_dict['errorLocation'],
error_dict['message']
)
return utils.error_msg_from_exception(e)


class MssqlEngineSpec(BaseEngineSpec):
engine = 'mssql'
Expand Down
2 changes: 1 addition & 1 deletion superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def handle_error(msg):
result_proxy = engine.execute(query.executed_sql, schema=query.schema)
except Exception as e:
logging.exception(e)
handle_error(utils.error_msg_from_exception(e))
handle_error(db_engine_spec.extract_error_message(e))

cursor = result_proxy.cursor
query.status = QueryStatus.RUNNING
Expand Down

0 comments on commit fc85034

Please sign in to comment.