diff --git a/IPython/nbconvert/nbconvertapp.py b/IPython/nbconvert/nbconvertapp.py index 99f1427..d625371 100755 --- a/IPython/nbconvert/nbconvertapp.py +++ b/IPython/nbconvert/nbconvertapp.py @@ -32,6 +32,7 @@ from IPython.utils.importstring import import_item from .exporters.export import export_by_name, get_export_names, ExporterNameError from IPython.nbconvert import exporters, transformers, writers from .utils.base import NbConvertBase +from .utils.exceptions import ConversionException #----------------------------------------------------------------------------- #Classes and functions @@ -203,12 +204,20 @@ class NbConvertApp(BaseIPythonApplication): resources=resources, config=self.config) except ExporterNameError as e: - print("Error: '%s' exporter not found." % self.export_format, + print("Error while converting '%s': '%s' exporter not found." + %(notebook_filename, self.export_format), file=sys.stderr) print("Known exporters are:", "\n\t" + "\n\t".join(get_export_names()), file=sys.stderr) sys.exit(-1) + except ConversionException as e: + print("Error while converting '%s': %s" %(notebook_filename, e), + file=sys.stderr) + sys.exit(-1) + # except Exception as e: + # print("Error: could not export '%s'" % notebook_filename, file=sys.stderr) + # print(e, file=sys.stderr) else: self.writer.write(output, resources, notebook_name=notebook_name) conversion_success += 1 diff --git a/IPython/nbconvert/utils/exceptions.py b/IPython/nbconvert/utils/exceptions.py index 6a4e0e6..58fff26 100644 --- a/IPython/nbconvert/utils/exceptions.py +++ b/IPython/nbconvert/utils/exceptions.py @@ -14,4 +14,4 @@ class ConversionException(Exception): """An exception raised by the conversion process.""" - pass \ No newline at end of file + pass diff --git a/IPython/nbconvert/utils/pandoc.py b/IPython/nbconvert/utils/pandoc.py index c853d3c..4be14bb 100644 --- a/IPython/nbconvert/utils/pandoc.py +++ b/IPython/nbconvert/utils/pandoc.py @@ -19,16 +19,14 @@ import subprocess # IPython imports from IPython.utils.py3compat import cast_bytes +from .exceptions import ConversionException + #----------------------------------------------------------------------------- # Classes and functions #----------------------------------------------------------------------------- -class PandocMissing(SystemExit): - """Exception raised when Pandoc is missing. - - A subclass of SystemExit so it will cause an exit if not caught, but - explicitly named so that it's possible to catch. - """ +class PandocMissing(ConversionException): + """Exception raised when Pandoc is missing. """ pass @@ -61,7 +59,7 @@ def pandoc(source, fmt, to, extra_args=None, encoding='utf-8'): ) except OSError as e: raise PandocMissing( - "Error trying to run '%s': %s.\n" %(" ".join(command), e) + + "The command '%s' returned an error: %s.\n" %(" ".join(command), e) + "Please check that pandoc is installed:\n" + "http://johnmacfarlane.net/pandoc/installing.html" )