James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.42k stars 519 forks source link

Class and Package Errors don't get their line associated #4288

Closed Cube707 closed 3 weeks ago

Cube707 commented 3 weeks ago

Pre-checks

Environment

The Issue

If a class / package author uses \PackageError or \ClassError, the error-line will always be reported as line 1, even if the logs contain a different, more exact line number.

Reproduction Steps

  1. compile the following MWE using pdflatex -interaction=nonstopmode testing.tex

    \documentclass{article}
    
    \newcommand\myclasscommanda{\ClassWarning{MyClass}{This is a Warning}}
    \newcommand\myclasscommandb{\ClassError{MyClass}{This is a error}{}}
    
    \newcommand\mypackagecommanda{\PackageWarning{MyPackage}{This is a Warning}}
    \newcommand\mypackagecommandb{\PackageError{MyPackage}{This is a error}{}}
    
    \begin{document}
    
    Hello
    \myclasscommanda
    \myclasscommandb
    \mypackagecommanda
    \mypackagecommandb
    World
    
    \end{document}
  2. note that LaTeX-Workshop reports the Warnings as line 12 and line 14, but both errors get reported as line 1 image

Expected Behavior

The errors should be reported as on line 13 and 14 and the commands responsible for the error should be marked

Logs

I assume the different behavior comes from the different format in the logs. Warning get the linenumber reported on the same line as the message, while errors get the linenumber reported on a later line:

Class MyClass Warning: This is a Warning on input line 12.

! Class MyClass Error: This is a error.

See the MyClass class documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.13 \myclasscommandb

Full testing.log

This is pdfTeX, Version 3.141592653-2.6-1.40.25 (MiKTeX 24.1) (preloaded format=pdflatex 2024.1.31)  18 JUN 2024 11:12
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**./testing.tex
(testing.tex
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-01-22>
(C:\ProgStuff\MiKTeX\tex/latex/base\article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(C:\ProgStuff\MiKTeX\tex/latex/base\size10.clo
File: size10.clo 2023/05/17 v1.4n Standard LaTeX file (size option)
)
\c@part=\count187
\c@section=\count188
\c@subsection=\count189
\c@subsubsection=\count190
\c@paragraph=\count191
\c@subparagraph=\count192
\c@figure=\count193
\c@table=\count194
\abovecaptionskip=\skip48
\belowcaptionskip=\skip49
\bibindent=\dimen140
)
(C:\ProgStuff\MiKTeX\tex/latex/l3backend\l3backend-pdftex.def
File: l3backend-pdftex.def 2024-01-04 L3 backend support: PDF output (pdfTeX)
\l__color_backend_stack_int=\count195
\l__pdf_internal_box=\box51
)
No file testing.aux.
\openout1 = `testing.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 9.
LaTeX Font Info:    ... okay on input line 9.

Class MyClass Warning: This is a Warning on input line 12.

! Class MyClass Error: This is a error.

See the MyClass class documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.13 \myclasscommandb

This error message was generated by an \errmessage
command, so I can't give any explicit help.
Pretend that you're Hercule Poirot: Examine all clues,
and deduce the truth by order and method.

Package MyPackage Warning: This is a Warning on input line 14.

! Package MyPackage Error: This is a error.

See the MyPackage package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.15 \mypackagecommandb

(That was another \errmessage.)

[1

{C:/Users/jan/AppData/Local/MiKTeX/fonts/map/pdftex/pdftex.map}] (testing.aux)
 ***********
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-01-22>
 ***********
 ) 
Here is how much of TeX's memory you used:
 429 strings out of 474503
 8171 string characters out of 5754855
 1922978 words of memory out of 5000000
 22761 multiletter control sequences out of 15000+600000
 558069 words of font info for 36 fonts, out of 8000000 for 9000
 1141 hyphenation exceptions out of 8191
 35i,5n,50p,130b,109s stack positions out of 10000i,1000n,20000p,200000b,200000s
<C:/ProgStuff/MiKTeX/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on testing.pdf (1 page, 12842 bytes).
PDF statistics:
 11 PDF objects out of 1000 (max. 8388607)
 0 named destinations out of 1000 (max. 500000)
 1 words of extra memory for PDF output out of 10000 (max. 10000000)
James-Yu commented 3 weeks ago

I don't see the problem. Have you tried removing -interaction=nonstopmode ? Not sure if that caused the problem.

image
Cube707 commented 3 weeks ago

Found it, I also need -file-line-error in addition to -interaction=nonstopmode.

Removing -interaction=nonstopmode makes pdflatex wait for input on every error, so the compilation runs forever...

Cube707 commented 3 weeks ago

still interesting that the error line now gets reported two times in the logs 🤷‍♂️​ image