Catch exception if LaTeX fails for child preview

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.
This commit is contained in:
Scott Kostyshak 2020-11-25 15:34:07 -05:00
parent 17ebec693a
commit c81bb47e49

View 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);
}
}