##// END OF EJS Templates
Catch ConversionExceptions in main nbconvert loop
David Wolever -
Show More
@@ -32,6 +32,7 b' from IPython.utils.importstring import import_item'
32 32 from .exporters.export import export_by_name, get_export_names, ExporterNameError
33 33 from IPython.nbconvert import exporters, transformers, writers
34 34 from .utils.base import NbConvertBase
35 from .utils.exceptions import ConversionException
35 36
36 37 #-----------------------------------------------------------------------------
37 38 #Classes and functions
@@ -203,12 +204,20 b' class NbConvertApp(BaseIPythonApplication):'
203 204 resources=resources,
204 205 config=self.config)
205 206 except ExporterNameError as e:
206 print("Error: '%s' exporter not found." % self.export_format,
207 print("Error while converting '%s': '%s' exporter not found."
208 %(notebook_filename, self.export_format),
207 209 file=sys.stderr)
208 210 print("Known exporters are:",
209 211 "\n\t" + "\n\t".join(get_export_names()),
210 212 file=sys.stderr)
211 213 sys.exit(-1)
214 except ConversionException as e:
215 print("Error while converting '%s': %s" %(notebook_filename, e),
216 file=sys.stderr)
217 sys.exit(-1)
218 # except Exception as e:
219 # print("Error: could not export '%s'" % notebook_filename, file=sys.stderr)
220 # print(e, file=sys.stderr)
212 221 else:
213 222 self.writer.write(output, resources, notebook_name=notebook_name)
214 223 conversion_success += 1
1 NO CONTENT: modified file
@@ -19,16 +19,14 b' import subprocess'
19 19 # IPython imports
20 20 from IPython.utils.py3compat import cast_bytes
21 21
22 from .exceptions import ConversionException
23
22 24 #-----------------------------------------------------------------------------
23 25 # Classes and functions
24 26 #-----------------------------------------------------------------------------
25 27
26 class PandocMissing(SystemExit):
27 """Exception raised when Pandoc is missing.
28
29 A subclass of SystemExit so it will cause an exit if not caught, but
30 explicitly named so that it's possible to catch.
31 """
28 class PandocMissing(ConversionException):
29 """Exception raised when Pandoc is missing. """
32 30 pass
33 31
34 32
@@ -61,7 +59,7 b" def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'):"
61 59 )
62 60 except OSError as e:
63 61 raise PandocMissing(
64 "Error trying to run '%s': %s.\n" %(" ".join(command), e) +
62 "The command '%s' returned an error: %s.\n" %(" ".join(command), e) +
65 63 "Please check that pandoc is installed:\n" +
66 64 "http://johnmacfarlane.net/pandoc/installing.html"
67 65 )
General Comments 0
You need to be logged in to leave comments. Login now