Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Jul 28, 2016
1 parent 2c3fbb4 commit 29538cd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions caravel/assets/javascripts/SqlLab/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Security per-database
* Overwrite workspace query
* Async
* Refactor timer in to its own thing


## Cosmetic
Expand Down
5 changes: 3 additions & 2 deletions caravel/assets/javascripts/SqlLab/components/Workspace.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PropTypes } from 'react'
import { Alert, Button, ButtonGroup } from 'react-bootstrap'
import { Alert, Button, ButtonGroup, Label } from 'react-bootstrap'
import Link from './Link'
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
Expand Down Expand Up @@ -115,7 +115,8 @@ const Workspace = React.createClass({
return (
<div className="panel panel-default Workspace">
<div className="panel-heading">
Workspace
<i className="fa fa-flask"/>
SQL Lab <Label bsStyle="warning">BETA</Label>
</div>
<div className="panel-body">
<div>
Expand Down
13 changes: 13 additions & 0 deletions caravel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,19 @@ def json_int_dttm_ser(obj):
return obj


def error_msg_from_exception(e):
"""Translate exception into error message
Database have different ways to handle exception. This function attempts
to make sense of the exception object and construct a human readable
sentence.
"""
default_msg = "{}".format(e)
if (hasattr(e, 'orig') and hasattr(e.orig, 'message')):
return e.orig.message.get('message', default_msg)
return default_msg


def markdown(s, markup_wrap=False):
s = s or ''
s = md(s, [
Expand Down
17 changes: 11 additions & 6 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def explore(self, datasource_type, datasource_id):
form_data=request.args,
slice_=slc)
except Exception as e:
flash(str(e), "danger")
flash(utils.error_msg_from_exception(e), "danger")
return redirect(error_redirect)
if request.args.get("json") == "true":
status = 200
Expand All @@ -880,7 +880,7 @@ def explore(self, datasource_type, datasource_id):
payload = obj.get_json()
except Exception as e:
logging.exception(e)
payload = str(e)
payload = utils.error_msg_from_exception(e)
status = 500
resp = Response(
payload,
Expand Down Expand Up @@ -910,7 +910,7 @@ def explore(self, datasource_type, datasource_id):
if config.get("DEBUG"):
raise(e)
return Response(
str(e),
utils.error_msg_from_exception(e),
status=500,
mimetype="application/json")
return resp
Expand Down Expand Up @@ -1197,7 +1197,12 @@ def sql(self, database_id):
def table(self, database_id, table_name):
mydb = db.session.query(models.Database).filter_by(id=database_id).one()
cols = []
t = mydb.get_columns(table_name)
try:
t = mydb.get_columns(table_name)
except Exception as e:
return Response(
json.dumps({'error': utils.error_msg_from_exception(e)}),
mimetype="application/json")
for col in t:
dtype = ""
try:
Expand Down Expand Up @@ -1270,7 +1275,7 @@ def runsql(self):
content = (
'<div class="alert alert-danger">'
"{}</div>"
).format(e.message)
).format(utils.error_msg_from_exception(e))
session.commit()
return content

Expand Down Expand Up @@ -1308,7 +1313,7 @@ def runsql(self):
df = pd.read_sql_query(sql=sql, con=eng)
df = df.fillna(0) # TODO
except Exception as e:
error_msg = "{}".format(e)
error_msg = utils.error_msg_from_exception(e)

session.commit()
if error_msg:
Expand Down

0 comments on commit 29538cd

Please sign in to comment.