This question "has been asked before" Trapping LaTeX error/warning but I would like to be more specific. I use only lualatex on Linux.
In my usage, a properly-compiled lualatex document has a proprietary "seal of approval" added at its end, using immediate\write. That speeds the workflow when the PDF is sent out. The "seal of approval" does not mean that the file looks pretty or has meaningful content. It only means that the PDF was processed according to certain standards, which are outside the scope of TeX.
If compilation throws a ClassError or PackageError, I can trap them (I believe) by using
the etoolbox macro \pretocmd. My prepended code sets a binary flag to true. The flag means that an error was thrown. When processing gets to the point where it will write
the "seal of approval" it will not do that, if the flag was set. Might still get a PDF, but no seal.
But I see that there are also some errors that do not originate from packages that I can easily identify. I suppose they come from the bare-metal binaries. Is there a way to deal with that? This is my question.
Note: I could launch lualatex as a subprocess of a BASH script, and deal with it that way.
That would allow me to put options on the lualatex command line, inspect the log file after completing, and deleted the PDF if erroneous. Seems bit brutal. But I cannot use --shell-escape within the document.
I do not care about fatal errors. They would not reach the "seal of approval" stage.
Also note that I am not the only user. Although I know that I should halt on any error, other users may simply hit return and continue.
show_error_hookcallback. – Ulrike Fischer Feb 18 '23 at 21:43show_error_hook, works. I use the good/bad to set a boolean false when bad. – rallg Feb 19 '23 at 19:42