").text( + "The save operation succeeded," + + " but the notebook does not appear to be valid." + + " The validation error was:" + )).append($("
").text(data.message) + )); + dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, + title: title, + body: body, + buttons : { + OK : { + "class" : "btn-primary" + } + } + }); + } this.events.trigger('notebook_saved.Notebook'); this._update_autosave_interval(start); if (this._checkpoint_after_save) { @@ -2278,7 +2304,57 @@ define([ * @param {jqXHR} xhr jQuery Ajax object */ Notebook.prototype.load_notebook_success = function (data, status, xhr) { - this.fromJSON(data); + var failed; + try { + this.fromJSON(data); + } catch (e) { + failed = e; + console.log("Notebook failed to load from JSON:", e); + } + if (failed || data.message) { + // *either* fromJSON failed or validation failed + var body = $(""); + var title; + if (failed) { + title = "Notebook failed to load"; + body.append($("").text( + "The error was: " + )).append($("
").addClass("js-error").text( + failed.toString() + )).append($("").text( + "See the error console for details." + )); + } else { + title = "Notebook validation failed"; + } + + if (data.message) { + var msg; + if (failed) { + msg = "The notebook also failed validation:" + } else { + msg = "An invalid notebook may not function properly." + + " The validation error was:" + } + body.append($("
").text( + msg + )).append($("
").addClass("validation-error").append( + $("").text(data.message) + )); + } + + dialog.modal({ + notebook: this, + keyboard_manager: this.keyboard_manager, + title: title, + body: body, + buttons : { + OK : { + "class" : "btn-primary" + } + } + }); + } if (this.ncells() === 0) { this.insert_cell_below('code'); this.edit_mode(0);