]> git.lyx.org Git - features.git/commitdiff
Catch exception if LaTeX fails for child preview
authorScott Kostyshak <skostysh@lyx.org>
Wed, 25 Nov 2020 20:34:07 +0000 (15:34 -0500)
committerScott Kostyshak <skostysh@lyx.org>
Wed, 25 Nov 2020 20:34:58 +0000 (15:34 -0500)
The exception is raised when an included file fails to export
because e.g. it is from a newer version of LyX or because an
intermediate command such as knitr fails.

The exception was introduced at 1a374a93 so that the export of a
document exits with error if an included document exports with
error.

This commit catches the exception when the LaTeX is asked for in
order to generate a preview of the included file.

src/insets/InsetInclude.cpp

index 07f5eece56993cf01ccc8bd166e052c2f2c4af75..bf9e1f5b61ff85a0d3227775dfaf83b22e253cea 100644 (file)
@@ -1308,7 +1308,19 @@ void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
        InsetCommandParams const & params = inset.params();
        if (RenderPreview::previewText() && preview_wanted(params, buffer)) {
                renderer.setAbsFile(includedFileName(buffer, params));
-               docstring const snippet = latexString(inset);
+               docstring snippet;
+               try {
+                       // InsetInclude::latex() throws if generation of LaTeX
+                       // fails, e.g. if lyx2lyx fails because file is too
+                       // new, or knitr fails.
+                       snippet = latexString(inset);
+               } catch (...) {
+                       // remove current preview because it is likely
+                       // associated with the previous included file name
+                       renderer.removePreview(buffer);
+                       LYXERR0("Preview of include failed.");
+                       return;
+               }
                renderer.addPreview(snippet, buffer);
        }
 }