Просмотр исходного кода

Merge pull request #16397 from overleaf/mj-logparser-missed-error

[web] Stop wrapping potential errors into previous log lines

GitOrigin-RevId: 892fc19e2e7886afa3dc011315879fa992f94877
Mathias Jakobsen 2 лет назад
Родитель
Сommit
d7a4061486

+ 7 - 2
services/web/frontend/js/ide/log-parser/latex-log-parser.js

@@ -346,16 +346,21 @@ class LogText {
       // append this line to it.
       // Some lines end with ... when LaTeX knows it's hit the limit
       // These shouldn't be wrapped.
+      // If the next line looks like it could be an error (i.e. start with a !),
+      // do not unwrap the line.
       const prevLine = wrappedLines[i - 1]
       const currentLine = wrappedLines[i]
 
-      if (prevLine.length === LOG_WRAP_LIMIT && prevLine.slice(-3) !== '...') {
+      if (
+        prevLine.length === LOG_WRAP_LIMIT &&
+        prevLine.slice(-3) !== '...' &&
+        currentLine.charAt(0) !== '!'
+      ) {
         this.lines[this.lines.length - 1] += currentLine
       } else {
         this.lines.push(currentLine)
       }
     }
-
     this.row = 0
   }
 

+ 19 - 0
services/web/test/frontend/helpers/fixtures/logs/lncs-undefined-control-sequence.log

@@ -0,0 +1,19 @@
+This is pdfTeX, Version 3.141592653-2.6-1.40.25 (TeX Live 2023) (preloaded format=latex 2023.8.28)  4 JAN 2024 10:26
+entering extended mode
+ \write18 enabled.
+ %&-line parsing enabled.
+**main.tex
+(./main.tex
+LaTeX2e <2023-06-01> patch level 1
+L3 programming layer <2023-06-30>
+(Font)              Font shape `OT1/cmss/m/sl' tried instead on input line 100.
+! Undefined control sequence.
+l.102         but here: "\anUndefinedCommand
+                                            " lorem ipsum ...
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
+
+Output written on output.dvi (1 page, 796 bytes).

+ 10 - 0
services/web/test/frontend/ide/log-parser/logParserTests.js

@@ -417,6 +417,16 @@ describe('logParser', function (done) {
       [8, 'LaTeX Error: Illegal character in array arg.', './main.tex'],
     ])
   })
+
+  it('should not unwrap errors into previous line', function () {
+    const { errors, warnings } = parseLatexLog(
+      'lncs-undefined-control-sequence.log'
+    )
+    expect(warnings).to.be.empty
+    expect(errors.map(x => [x.line, x.message, x.file])).to.deep.equal([
+      [102, 'Undefined control sequence.', './main.tex'],
+    ])
+  })
 })
 
 function readLog(filename) {