From 6b2607530f3c304dd72b331e36740b45d1bbd540 2014-08-14 00:46:59 From: Thomas Kluyver <takowl@gmail.com> Date: 2014-08-14 00:46:59 Subject: [PATCH] Merge pull request #6303 from minrk/nbformat-error Fix error message when failing to load a notebook --- diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 5923256..bb903ad 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -514,15 +514,20 @@ define([ } }; + var ajax_error_msg = function (jqXHR) { + // Return a JSON error message if there is one, + // otherwise the basic HTTP status text. + if (jqXHR.responseJSON && jqXHR.responseJSON.message) { + return jqXHR.responseJSON.message; + } else { + return jqXHR.statusText; + } + } var log_ajax_error = function (jqXHR, status, error) { // log ajax failures with informative messages var msg = "API request failed (" + jqXHR.status + "): "; console.log(jqXHR); - if (jqXHR.responseJSON && jqXHR.responseJSON.message) { - msg += jqXHR.responseJSON.message; - } else { - msg += jqXHR.statusText; - } + msg += ajax_error_msg(jqXHR); console.log(msg); }; @@ -547,6 +552,7 @@ define([ platform: platform, is_or_has : is_or_has, is_focused : is_focused, + ajax_error_msg : ajax_error_msg, log_ajax_error : log_ajax_error, }; diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 02a4439..e22fd51 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -2286,13 +2286,14 @@ define([ */ Notebook.prototype.load_notebook_error = function (xhr, status, error) { this.events.trigger('notebook_load_failed.Notebook', [xhr, status, error]); + utils.log_ajax_error(xhr, status, error); var msg; if (xhr.status === 400) { - msg = error; + msg = escape(utils.ajax_error_msg(xhr)); } else if (xhr.status === 500) { msg = "An unknown error occurred while loading this notebook. " + "This version can load notebook formats " + - "v" + this.nbformat + " or earlier."; + "v" + this.nbformat + " or earlier. See the server log for details."; } dialog.modal({ notebook: this, @@ -2567,10 +2568,10 @@ define([ * @method delete_checkpoint_error * @param {jqXHR} xhr jQuery Ajax object * @param {String} status Description of response status - * @param {String} error_msg HTTP error message + * @param {String} error HTTP error message */ - Notebook.prototype.delete_checkpoint_error = function (xhr, status, error_msg) { - this.events.trigger('checkpoint_delete_failed.Notebook'); + Notebook.prototype.delete_checkpoint_error = function (xhr, status, error) { + this.events.trigger('checkpoint_delete_failed.Notebook', [xhr, status, error]); }; diff --git a/IPython/nbformat/reader.py b/IPython/nbformat/reader.py index 78e8a1d..bb94ee4 100644 --- a/IPython/nbformat/reader.py +++ b/IPython/nbformat/reader.py @@ -80,6 +80,8 @@ def reads(s, **kwargs): nb : NotebookNode The notebook that was read. """ + from .current import NBFormatError + nb_dict = parse_json(s, **kwargs) (major, minor) = get_version(nb_dict) if major in versions: