##// END OF EJS Templates
better message when notebook format is not supported...
MinRK -
Show More
@@ -146,8 +146,9 b' class FileNotebookManager(NotebookManager):'
146 146 try:
147 147 # v1 and v2 and json in the .ipynb files.
148 148 nb = current.reads(s, u'json')
149 except Exception as e:
150 raise web.HTTPError(500, u'Unreadable JSON notebook: %s' % e)
149 except ValueError as e:
150 msg = u"Unreadable Notebook: %s" % e
151 raise web.HTTPError(400, msg, reason=msg)
151 152 return last_modified, nb
152 153
153 154 def read_notebook_object(self, notebook_id):
@@ -1794,20 +1794,20 b' var IPython = (function (IPython) {'
1794 1794 * @param {String} errorThrow HTTP error message
1795 1795 */
1796 1796 Notebook.prototype.load_notebook_error = function (xhr, textStatus, errorThrow) {
1797 if (xhr.status === 500) {
1798 var msg = "An error occurred while loading this notebook. Most likely " +
1799 "this notebook is in a newer format than is supported by this " +
1800 "version of IPython. This version can load notebook formats " +
1801 "v"+this.nbformat+" or earlier.";
1802
1803 IPython.dialog.modal({
1804 title: "Error loading notebook",
1805 body : msg,
1806 buttons : {
1807 "OK": {}
1808 }
1809 });
1797 if (xhr.status === 400) {
1798 var msg = errorThrow;
1799 } else if (xhr.status === 500) {
1800 var msg = "An unknown error occurred while loading this notebook. " +
1801 "This version can load notebook formats " +
1802 "v" + this.nbformat + " or earlier.";
1810 1803 }
1804 IPython.dialog.modal({
1805 title: "Error loading notebook",
1806 body : msg,
1807 buttons : {
1808 "OK": {}
1809 }
1810 });
1811 1811 }
1812 1812
1813 1813 /********************* checkpoint-related *********************/
@@ -40,14 +40,19 b' current_nbformat = nbformat'
40 40 current_nbformat_minor = nbformat_minor
41 41
42 42
43 class NBFormatError(ValueError):
44 pass
43 45
44 class NBFormatError(Exception):
46 class NotJSONError(ValueError):
45 47 pass
46 48
47 49
48 50 def parse_json(s, **kwargs):
49 51 """Parse a string into a (nbformat, dict) tuple."""
50 d = json.loads(s, **kwargs)
52 try:
53 d = json.loads(s, **kwargs)
54 except ValueError:
55 raise NotJSONError("Notebook does not appear to be JSON: %r" % s[:16])
51 56 nbf = d.get('nbformat', 1)
52 57 nbm = d.get('nbformat_minor', 0)
53 58 return nbf, nbm, d
@@ -82,7 +87,7 b' def reads_json(s, **kwargs):'
82 87 nb = v3.to_notebook_json(d, **kwargs)
83 88 nb = v3.convert_to_this_nbformat(nb, orig_version=3, orig_minor=minor)
84 89 else:
85 raise NBFormatError('Unsupported JSON nbformat version: %i' % nbf)
90 raise NBFormatError('Unsupported JSON nbformat version %s (supported version: %i)' % (nbf, 3))
86 91 return nb
87 92
88 93
General Comments 0
You need to be logged in to leave comments. Login now