Add limit to log parsing for react log viewer (#6213)

* Add limit to log parsing for react log viewer

GitOrigin-RevId: e2e5ffd6eaf1c207cc4f49fb5c637457990c328e
This commit is contained in:
Miguel Serrano 2022-01-11 18:19:38 +01:00 committed by Copybot
parent cf4269d4ee
commit 35396ab61a
3 changed files with 28 additions and 15 deletions

View file

@ -104,7 +104,9 @@ export const handleOutputFiles = async (projectId, data) => {
const log = await response.text()
try {
const { errors, warnings } = new BibLogParser(log, {}).parse()
const { errors, warnings } = new BibLogParser(log, {
maxErrors: 100,
}).parse()
accumulateResults({ errors, warnings }, 'BibTeX:')
} catch (e) {
// BibLog parsing errors are ignored

View file

@ -18,7 +18,7 @@ const MESSAGE_LEVELS = {
ERROR: 'error',
}
const parserReducer = function (maxErrors) {
const parserReducer = function (maxErrors, buildMaxErrorsReachedMessage) {
return function (accumulator, parser) {
const consume = function (logText, regex, process) {
let match
@ -32,16 +32,18 @@ const parserReducer = function (maxErrors) {
// 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)
if (maxErrors != null && iterationCount >= maxErrors) {
if (buildMaxErrorsReachedMessage) {
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, '']
}
@ -171,11 +173,17 @@ export default class BibLogParser {
}
// reduce over the parsers, starting with the log text,
let [allWarnings, remainingText] = this.warningParsers.reduce(
parserReducer(this.options.maxErrors),
parserReducer(
this.options.maxErrors,
this.options.buildMaxErrorsReachedMessage
),
[[], this.text]
)
;[allErrors, remainingText] = this.errorParsers.reduce(
parserReducer(this.options.maxErrors),
parserReducer(
this.options.maxErrors,
this.options.buildMaxErrorsReachedMessage
),
[[], remainingText]
)
result.warnings = allWarnings

View file

@ -640,7 +640,10 @@ App.controller(
}
function processBiber(log) {
const bibLogParser = new BibLogParser(log, { maxErrors: 100 })
const bibLogParser = new BibLogParser(log, {
maxErrors: 100,
buildMaxErrorsReachedMessage: true,
})
const { errors, warnings } = bibLogParser.parse(log, {})
const all = [].concat(errors, warnings)
accumulateResults({ type: 'BibTeX:', all, errors, warnings })