Kirill Simonov avatar Kirill Simonov committed ab9e537

tweak.shell: display error hints when available.

Comments (0)

Files changed (4)

src/htsql_tweak/shell/command.py

 
     def render_error(self, exc):
         detail = exc.detail
+        hint = None
         first_line = 'null'
         first_column = 'null'
         last_line = 'null'
             last_line = mark.input.count(u'\n', 0, last_break)
             first_column = mark.start-first_break
             last_column = mark.end-last_break
+            hint = exc.hint
         yield "{\n"
         yield "  \"type\": \"error\",\n"
         yield "  \"detail\": %s,\n" % escape(cgi.escape(detail))
+        yield "  \"hint\": %s,\n" % (escape(cgi.escape(hint))
+                                     if hint is not None else "null")
         yield "  \"first_line\": %s,\n" % first_line
         yield "  \"first_column\": %s,\n" % first_column
         yield "  \"last_line\": %s,\n" % last_line

src/htsql_tweak/shell/static/index.html

         <div id="error-panel" class="panel">
           <div class="alert">
             <pre id="error"></pre>
+            <pre id="error-hint"></pre>
             <button id="close-error" class="close">&times;</button>
           </div>
         </div>

src/htsql_tweak/shell/static/shell.js

             state.$panel.hide();
         state.$panel = $errorPanel.show();
         $error.html(output.detail);
+        if (output.hint) {
+            $errorHint.html("("+output.hint+")");
+        }
+        else {
+            $errorHint.html("");
+        }
         if (state.marker) {
             state.marker();
             state.marker = null;
     var $requestPanel = $('#request-panel');
     var $errorPanel = $('#error-panel');
     var $error = $('#error');
+    var $errorHint = $('#error-hint');
     var $failurePanel = $('#failure-panel');
     var $sqlPanel = $('#sql-panel');
     var $sql = $('#sql');

test/input/addon.yaml

     extensions:
       tweak.shell: {}
   - uri: /shell()
+    ignore: true
 
   # FIXME: add tests for auxiliary commands
 
   - uri: /
     headers:
       Accept: text/html
+    ignore: true
 
 # TWEAK.SQLALCHEMY - adapt to SQLAlchemy
 - py: has-sqlalchemy
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.