commit 1dbf0e5aab732bdba4eed1af2866c357bc30a526
Author: Scott Kostyshak <[email protected]>
Date: Fri Mar 20 00:40:01 2015 -0400
Check exit code of LaTeX process in LaTeX::run
Systemcall::startscript returns the exit code of the LaTeX command
that is run, but the return value was not being checked by
LaTeX::run. Instead, we relied on parsing log files. However, this
parsing is not perfect.
The return value is now checked and if the exit code of the command
is non-zero, an enum value is added to the return and the user is
notified of the error.
At a higher level, if the LaTeX command returns a non-zero exit code,
in the GUI a message such as
"Error while exporting format: PDF (LuaTeX)" will be given instead of
"Successful preview of format: PDF (LuaTeX)".
When run on the commandline, lyx -e lualatex example.lyx
will give "Error: LaTeX failed" and a non-zero exit code
where before it gave a zero exit code.
A real example of the bug this commit fixes is LyX's (as of this commit)
ACM-sigplan.lyx template.
Before this commit:
$ lyx -e pdf2 ACM-sigplan.lyx
[...snip...]
support/Systemcall.cpp (288): Systemcall: 'pdflatex "ACM-sigplan.tex"'
finished with exit code 1
$ echo $?
0
Starting with this commit:
$ mylyx master -e pdf2 ACM-sigplan.lyx
support/Systemcall.cpp (288): Systemcall: 'pdflatex "ACM-sigplan.tex"'
finished with exit code 1
Error: LaTeX failed
----------------------------------------
LaTeX did not run successfully. The command that was run exited with
error.
$ echo $?
1
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index 258d32b..6e9655e 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -52,6 +52,8 @@ Changes with respect to external programs and libraries in
2.2:
run LyX against Qt 4.8.x. On Windows, Qt 4.8.5 suffers from a bug that
breaks the use of shortcuts, so on Windows Qt 4.8.4 is advised.
+- LyX now gives an error if the underlying LaTeX command exited with error.
+
Known issues in version 2.2.0
-----------------------------
diff --git a/src/Converter.cpp b/src/Converter.cpp
index b78ee90..933e2f6 100644
--- a/src/Converter.cpp
+++ b/src/Converter.cpp
@@ -660,6 +660,14 @@ bool Converters::runLaTeX(Buffer const & buffer, string
const & command,
"Additionally, LyX could not
locate "
"the LaTeX log %1$s."),
from_utf8(name));
Alert::error(_("LaTeX failed"), str);
+ } else if (result & LaTeX::NONZERO_ERROR) {
+ docstring const str =
+ bformat(_( "The external program\n%1$s\n"
+ "finished with an error. "
+ "It is recommended you fix the cause of the
external "
+ "program's error (check the logs). "),
from_utf8(command));
+ // FIXME: In LyX 2.3.0 the warning will be converted to an
error.
+ Alert::error(_("LaTeX failed"), str);
} else if (result & LaTeX::NO_OUTPUT) {
Alert::warning(_("Output is empty"),
_("No output file was generated."));
diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index 22e32d3..588ca52 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -226,7 +226,8 @@ int LaTeX::run(TeXErrors & terr)
LYXERR(Debug::LATEX, "Run #" << count);
message(runMessage(count));
- startscript();
+ int const exit_code = startscript();
+
scanres = scanLogFile(terr);
if (scanres & ERROR_RERUN) {
LYXERR(Debug::LATEX, "Rerunning LaTeX");
@@ -422,6 +423,7 @@ int LaTeX::run(TeXErrors & terr)
// Write the dependencies to file.
head.write(depfile);
+
if (scanres & NO_OUTPUT) {
// A previous run could have left a PDF and since
// no PDF is created if NO_OUTPUT, we remove any
@@ -431,6 +433,10 @@ int LaTeX::run(TeXErrors & terr)
// be the same so any lingering PDF will be viewed.
deleteFilesOnError();
}
+
+ if (exit_code)
+ scanres |= NONZERO_ERROR;
+
LYXERR(Debug::LATEX, "Done.");
return scanres;
}
diff --git a/src/LaTeX.h b/src/LaTeX.h
index 615d974..7fa6798 100644
--- a/src/LaTeX.h
+++ b/src/LaTeX.h
@@ -138,10 +138,12 @@ public:
///
BIBTEX_ERROR = 16384,
///
+ NONZERO_ERROR = 32768, // the command exited with nonzero status
+ ///
//FIXME: BIBTEX_ERROR has been removed from ERRORS for now,
since users were irritated
// about those errors which prevented compilation of
previously compiling documents.
// Think about a "gentle" transfer to BibTeX error
reporting.
- ERRORS = TEX_ERROR + LATEX_ERROR,
+ ERRORS = TEX_ERROR + LATEX_ERROR + NONZERO_ERROR,
///
WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
};