]> git.lyx.org Git - lyx.git/commitdiff
Check exit code of LaTeX process in LaTeX::run
authorScott Kostyshak <skostysh@lyx.org>
Fri, 20 Mar 2015 04:40:01 +0000 (00:40 -0400)
committerScott Kostyshak <skostysh@lyx.org>
Fri, 20 Mar 2015 06:19:44 +0000 (02:19 -0400)
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

RELEASE-NOTES
src/Converter.cpp
src/LaTeX.cpp
src/LaTeX.h

index 258d32b487a59e895a680e1ac73fda3c17e08f5f..6e9655e9bec01339a08c61efd3feae4aff837981 100644 (file)
@@ -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
 -----------------------------
index b78ee90b454adaced3d421d851ee329a74dc54d3..933e2f673b4d63be480adf1c07b80b067c26cec4 100644 (file)
@@ -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."));
index 22e32d35c33569fe20d647cefb6e55350b9eedf9..588ca522e4432d7129e90a7e776f334bb310cf21 100644 (file)
@@ -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;
 }
index 615d974f2cd0e54ca4d3525bb0d1989cdf559802..7fa6798ff05cdbee0aad6a6dfdeb47f66c941aa7 100644 (file)
@@ -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
        };