From bb8a0943105f2c2a4e295de276a68a16a84f00aa Mon Sep 17 00:00:00 2001 From: Ned Letcher Date: Wed, 21 Feb 2018 01:44:08 +1100 Subject: [PATCH] fixed parsing errors not flowing back into interface --- bin/run-web | 7 +++---- typediff/server.py | 19 +++++++++++-------- typediff/typediff.py | 1 - www/static/typediff.js | 3 ++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/bin/run-web b/bin/run-web index c69caf1..15c872c 100755 --- a/bin/run-web +++ b/bin/run-web @@ -7,8 +7,8 @@ This script runs the typediff webapp. Options are: --port PORT Runs the app on port PORT. - --debug Runs mod_wsgi-express with --debug-mode and --enable-debugger - flags enabled. + --debug Runs mod_wsgi-express with --debug-mode, --enable-debugger + and --log-to-terminal flags enabled. --echo Don't run the app, just echo the underlying mod_wsgi-express command that would have been run with the configuration @@ -30,7 +30,7 @@ while [[ ${1} == --* ]]; do shift 2 ;; --debug) - DEBUGFLAGS="--debug-mode --enable-debugger" + DEBUGFLAGS="--log-to-terminal --debug-mode --enable-debugger" shift 1 ;; --echo) @@ -64,6 +64,5 @@ ${ECHO} mod_wsgi-express start-server \ --directory-index index.html \ --include-file httpd.conf \ --request-timeout 180 \ - --log-to-terminal \ --application-type module \ --entry-point typediff.wsgi diff --git a/typediff/server.py b/typediff/server.py index 6a64ad9..d5e67c8 100644 --- a/typediff/server.py +++ b/typediff/server.py @@ -9,17 +9,13 @@ from .config import LOGONROOT, TREEBANKLIST, FANGORNPATH, PROFILELIST from .gram import get_grammar, get_grammars from .delphin import (init_paths, JSONEncoder, load_hierarchy, Treebank, - dotdict, Profile) + dotdict, Profile, AceError) # set LOGONROOT environment variable in case it's not set init_paths(logonroot=LOGONROOT) from .typediff import typediff_web, process_sentences, process_profiles -# TODO: -# create a setup.py file with executable entry points for the main functions of: -# -- typediff.py, grammar-utils.py, type-stats.py, parseit.py, queryex.py, eval.py - app = Flask(__name__) app.json_encoder = JSONEncoder @@ -39,9 +35,16 @@ def parse_types(): pos_inputs = request.form.get('pos-items', '').strip().splitlines() neg_inputs = request.form.get('neg-items', '').strip().splitlines() - pos_items = process_sentences(pos_inputs, opts) - neg_items = process_sentences(neg_inputs, opts) - return jsonify(typediff_web(pos_items, neg_items, opts)) + try: + pos_items = process_sentences(pos_inputs, opts) + neg_items = process_sentences(neg_inputs, opts) + except AceError as e: + return jsonify({'success':False, 'error': e.msg}) + + data = typediff_web(pos_items, neg_items, opts) + data['success'] = True + + return jsonify(data) @app.route('/process-profiles', methods=['POST']) diff --git a/typediff/typediff.py b/typediff/typediff.py index d88a2a8..a817466 100755 --- a/typediff/typediff.py +++ b/typediff/typediff.py @@ -167,7 +167,6 @@ def type_data(): def typediff_web(pos_items, neg_items, opts): data = { - 'success': True, 'pos-items' : pos_items, 'neg-items' : neg_items, 'descendants' : load_descendants(opts.grammar) if opts.desc else False, diff --git a/www/static/typediff.js b/www/static/typediff.js index ecd285d..6eb73b9 100644 --- a/www/static/typediff.js +++ b/www/static/typediff.js @@ -449,7 +449,8 @@ function processPostData(data) { // applyFilters calls doDiff even when there are no filters(); applyFilters(); } else { - showStatusBox('#fail-box').html(data.error.replace(/\n/g, '
')); + $('#fail-box').html(data.error.replace(/\n/g, '
')); + showStatusBox('#fail-box'); updateButtons(); } }