From cf0a488a30657b061efb55140695089aafa55f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Alby?= Date: Tue, 14 Dec 2021 14:25:14 +0100 Subject: [PATCH] Merge pull request #6035 from overleaf/msm-remove-redundant-bibtex-error Remove redundant >100 bibtex errors message GitOrigin-RevId: b2487aaf3b31c469b5780f6d05e4cd124666adf5 --- .../js/ide/log-parser/bib-log-parser.js | 84 ++++++++++--------- .../js/ide/pdf/controllers/PdfController.js | 2 +- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/services/web/frontend/js/ide/log-parser/bib-log-parser.js b/services/web/frontend/js/ide/log-parser/bib-log-parser.js index f132370b5d..9068d82fc2 100644 --- a/services/web/frontend/js/ide/log-parser/bib-log-parser.js +++ b/services/web/frontend/js/ide/log-parser/bib-log-parser.js @@ -15,45 +15,49 @@ const MESSAGE_LEVELS = { ERROR: 'error', } -const parserReducer = function (accumulator, parser) { - const consume = function (logText, regex, process) { - let match - let text = logText - const result = [] - const re = regex - let iterationCount = 0 - while ((match = re.exec(text))) { - iterationCount += 1 - const newEntry = process(match) +const parserReducer = function (maxErrors) { + return function (accumulator, parser) { + const consume = function (logText, regex, process) { + let match + let text = logText + const result = [] + const re = regex + let iterationCount = 0 + while ((match = re.exec(text))) { + iterationCount += 1 + const newEntry = process(match) - // Too many log entries can cause browser crashes - // Construct a too many files error from the last match - const maxErrors = 100 - if (iterationCount >= maxErrors) { - const level = newEntry.level + 's' - newEntry.message = [ - 'Over', - maxErrors, - level, - 'returned. Download raw logs to see full list', - ].join(' ') - newEntry.line = undefined - result.unshift(newEntry) - return [result, ''] + // Too many log entries can cause browser crashes + // Construct a too many files error from the last match + if (iterationCount >= maxErrors) { + const level = newEntry.level + 's' + newEntry.message = [ + 'Over', + maxErrors, + level, + 'returned. Download raw logs to see full list', + ].join(' ') + newEntry.line = undefined + result.unshift(newEntry) + return [result, ''] + } + + result.push(newEntry) + text = + match.input.slice(0, match.index) + + match.input.slice( + match.index + match[0].length + 1, + match.input.length + ) } - - result.push(newEntry) - text = - match.input.slice(0, match.index) + - match.input.slice(match.index + match[0].length + 1, match.input.length) + return [result, text] } - return [result, text] - } - const [currentErrors, text] = accumulator - const [regex, process] = parser - const [errors, _remainingText] = consume(text, regex, process) - return [currentErrors.concat(errors), _remainingText] + const [currentErrors, text] = accumulator + const [regex, process] = parser + const [errors, _remainingText] = consume(text, regex, process) + return [currentErrors.concat(errors), _remainingText] + } } export default class BibLogParser { @@ -174,13 +178,13 @@ export default class BibLogParser { } // reduce over the parsers, starting with the log text, let [allWarnings, remainingText] = this.warningParsers.reduce( - parserReducer, + parserReducer(this.options.maxErrors), [[], this.text] ) - ;[allErrors, remainingText] = this.errorParsers.reduce(parserReducer, [ - [], - remainingText, - ]) + ;[allErrors, remainingText] = this.errorParsers.reduce( + parserReducer(this.options.maxErrors), + [[], remainingText] + ) result.warnings = allWarnings result.errors = allErrors result.all = allWarnings.concat(allErrors) diff --git a/services/web/frontend/js/ide/pdf/controllers/PdfController.js b/services/web/frontend/js/ide/pdf/controllers/PdfController.js index 304df438bf..20fc5f917f 100644 --- a/services/web/frontend/js/ide/pdf/controllers/PdfController.js +++ b/services/web/frontend/js/ide/pdf/controllers/PdfController.js @@ -646,7 +646,7 @@ App.controller( } function processBiber(log) { - const bibLogParser = new BibLogParser(log, {}) + const bibLogParser = new BibLogParser(log, { maxErrors: 100 }) const { errors, warnings } = bibLogParser.parse(log, {}) const all = [].concat(errors, warnings) accumulateResults({ type: 'BibTeX:', all, errors, warnings })