Commit 187cef14 authored by Jérome Perrin's avatar Jérome Perrin

Display a traceback in the GUI in case of errors

From George idea
parent 29773939
import json import json
import traceback
from pprint import pformat from pprint import pformat
from flask import Flask, jsonify, redirect, url_for from flask import Flask, jsonify, redirect, url_for
from flask import request from flask import request
...@@ -15,7 +16,12 @@ def front_page(): ...@@ -15,7 +16,12 @@ def front_page():
def runSimulation(): def runSimulation():
parameter_dict = request.json['json'] parameter_dict = request.json['json']
app.logger.debug("running with:\n%s" % (pformat(parameter_dict,))) app.logger.debug("running with:\n%s" % (pformat(parameter_dict,)))
return jsonify(json.loads(simulate_line_json(input_data=json.dumps(parameter_dict)))) try:
result = simulate_line_json(input_data=json.dumps(parameter_dict))
return jsonify(dict(success=json.loads(result)))
except Exception, e:
tb = traceback.format_exc()
return jsonify(dict(error=e.args[0], traceback=tb))
def main(*args): def main(*args):
app.run(debug=True) app.run(debug=True)
......
...@@ -127,12 +127,16 @@ ...@@ -127,12 +127,16 @@
function(e){ function(e){
dream_instance.runSimulation( dream_instance.runSimulation(
function(data) { function(data) {
$("#json_result").text(JSON.stringify(data, undefined, " ")); if (data['success']) {
$("#json_result").text(JSON.stringify(data['success'], undefined, " "));
$.each(data.coreObject, function(idx, obj){ $.each(data.coreObject, function(idx, obj){
var e = $("#" + obj.id); var e = $("#" + obj.id);
/* attach something to each corresponding core object */ /* attach something to each corresponding core object */
// e.tooltip(JSON.stringify(obj['results'], undefined, " ")); // e.tooltip(JSON.stringify(obj['results'], undefined, " "));
}) })
} else {
$("#json_result").effect('shake', 50).text(data['traceback']);
}
}); });
e.preventDefault(); e.preventDefault();
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment