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