Merge pull request #5721 from overleaf/hb-fix-log-line-parsing

Improve file line error log parser regex

GitOrigin-RevId: d3fbb39b4a6d99e339c1d6e6eb81d9cfb3ec5935
This commit is contained in:
Alf Eaton 2021-11-16 10:28:33 +00:00 committed by Copybot
parent 07361a8f68
commit 1fc57aadcf
3 changed files with 137 additions and 5 deletions

View file

@ -7,6 +7,7 @@ const PACKAGE_WARNING_REGEX = /^(Package \b.+\b Warning:.*)$/
const LINES_REGEX = /lines? ([0-9]+)/
// This is used to parse the package name from the package warnings
const PACKAGE_REGEX = /^Package (\b.+\b) Warning/
const FILE_LINE_ERROR_REGEX = /^([./].*):(\d+): (.*)/
const STATE = {
NORMAL: 0,
@ -83,7 +84,7 @@ export default class LatexParser {
}
currentLineIsFileLineError() {
return /^\/.*:\d+: .*/.test(this.currentLine)
return FILE_LINE_ERROR_REGEX.test(this.currentLine)
}
currentLineIsRunawayArgument() {
@ -103,7 +104,7 @@ export default class LatexParser {
}
parseFileLineError() {
const result = this.currentLine.match(/^(\/.*):(\d+): (.*)/)
const result = this.currentLine.match(FILE_LINE_ERROR_REGEX)
this.currentError = {
line: result[2],
file: result[1],

View file

@ -0,0 +1,105 @@
This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2021) (preloaded format=pdflatex 2021.9.30) 9 NOV 2021 16:55
entering extended mode
\write18 enabled.
%&-line parsing enabled.
**main.tex
(./main.tex
LaTeX2e <2021-06-01> patch level 1
L3 programming layer <2021-07-12> (/usr/local/texlive/2021/texmf-dist/tex/latex
/base/article.cls
Document Class: article 2021/02/12 v1.4n Standard LaTeX document class
(/usr/local/texlive/2021/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2021/02/12 v1.4n Standard LaTeX file (size option)
)
\c@part=\count182
\c@section=\count183
\c@subsection=\count184
\c@subsubsection=\count185
\c@paragraph=\count186
\c@subparagraph=\count187
\c@figure=\count188
\c@table=\count189
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
) (/usr/local/texlive/2021/texmf-dist/tex/latex/base/inputenc.sty
Package: inputenc 2021/02/14 v1.3d Input encoding file
\inpenc@prehook=\toks16
\inpenc@posthook=\toks17
) (/usr/local/texlive/2021/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def
File: l3backend-pdftex.def 2021-07-12 L3 backend support: PDF output (pdfTeX)
\l__color_backend_stack_int=\count190
\l__pdf_internal_box=\box50
) (./output.aux (./acks/name.aux))
\openout1 = `output.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 8.
LaTeX Font Info: ... okay on input line 8.
LaTeX Font Info: Checking defaults for OMS/cmsy/m/n on input line 8.
LaTeX Font Info: ... okay on input line 8.
LaTeX Font Info: Checking defaults for OT1/cmr/m/n on input line 8.
LaTeX Font Info: ... okay on input line 8.
LaTeX Font Info: Checking defaults for T1/cmr/m/n on input line 8.
LaTeX Font Info: ... okay on input line 8.
LaTeX Font Info: Checking defaults for TS1/cmr/m/n on input line 8.
LaTeX Font Info: ... okay on input line 8.
LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line 8.
LaTeX Font Info: ... okay on input line 8.
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line 8.
LaTeX Font Info: ... okay on input line 8.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <12> on input line 10.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <8> on input line 10.
LaTeX Font Info: External font `cmex10' loaded for size
(Font) <6> on input line 10.
[1
{/usr/local/texlive/2021/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
\openout2 = `acks/name.aux'.
(./acks/name.tex
! Misplaced alignment tab character &.
l.1 inserting an ampersand &
I can't figure out why you would want to use a tab mark
here. If you just want an ampersand, the remedy is
simple: Just type `I\&' now. But if some right brace
up above has ended a previous alignment prematurely,
you're probably due for more error messages, and you
might try typing `S' now just to see what is salvageable.
) [2
]
! Misplaced alignment tab character &.
l.14 &
I can't figure out why you would want to use a tab mark
here. If you just want an ampersand, the remedy is
simple: Just type `I\&' now. But if some right brace
up above has ended a previous alignment prematurely,
you're probably due for more error messages, and you
might try typing `S' now just to see what is salvageable.
(./output.aux (./acks/name.aux)) )
Here is how much of TeX's memory you used:
450 strings out of 478542
7915 string characters out of 5850413
299724 words of memory out of 5000000
18449 multiletter control sequences out of 15000+600000
407070 words of font info for 39 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
34i,6n,41p,150b,191s stack positions out of 5000i,500n,10000p,200000b,80000s
</usr/local/texlive/2021/texmf-dist/fonts/typ
e1/public/amsfonts/cm/cmbx12.pfb></usr/local/texlive/2021/texmf-dist/fonts/type
1/public/amsfonts/cm/cmr10.pfb></usr/local/texlive/2021/texmf-dist/fonts/type1/
public/amsfonts/cm/cmr12.pfb></usr/local/texlive/2021/texmf-dist/fonts/type1/pu
blic/amsfonts/cm/cmr17.pfb>
Output written on output.pdf (2 pages, 42045 bytes).
PDF statistics:
31 PDF objects out of 1000 (max. 8388607)
18 compressed objects within 1 object stream
0 named destinations out of 1000 (max. 500000)
1 words of extra memory for PDF output out of 10000 (max. 10000000)

View file

@ -77,6 +77,13 @@ describe('logParser', function (done) {
flag: 'r',
}
)
this.secondaryFileLineErrorLog = fs.readFileSync(
path.resolve(__dirname, fixturePath + 'file-line-error-2.log'),
{
encoding: 'utf8',
flag: 'r',
}
)
})
it('should parse errors', function () {
@ -401,10 +408,10 @@ describe('logParser', function (done) {
})
it('should perform file line error parsing', function () {
const latexParser = new LatexLogParser(this.fileLineErrorLog)
const errors = latexParser.parse().errors
let latexParser = new LatexLogParser(this.fileLineErrorLog)
let errors = latexParser.parse().errors
const expectedErrors = [
let expectedErrors = [
[
1,
'Undefined control sequence.',
@ -418,6 +425,25 @@ describe('logParser', function (done) {
[errors[i].line, errors[i].message, errors[i].file] + ''
)
}
// again with a more complex example
latexParser = new LatexLogParser(this.secondaryFileLineErrorLog)
errors = latexParser.parse().errors
expectedErrors = [
[1, 'Misplaced alignment tab character &.', './acks/name.tex'],
[14, 'Misplaced alignment tab character &.', './main.tex'],
]
expect(errors.length).to.equal(expectedErrors.length)
for (let i = 0; i < errors.length; i++) {
expect(expectedErrors[i]).to.deep.equal([
errors[i].line,
errors[i].message,
errors[i].file,
])
}
})
it('should ignore duplicates', function () {