Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error handling for presto #2161

Merged
merged 2 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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