Merge pull request #18140 from overleaf/ae-log-rules

Add new regular expressions for matching compiler error messages

GitOrigin-RevId: ab6e17951c29c2a68b385b7e0cb77abf2d22281d
This commit is contained in:
Alf Eaton 2024-04-30 10:33:45 +01:00 committed by Copybot
parent 13bb42885e
commit 8921b8484e
3 changed files with 1063 additions and 33 deletions

View file

@ -46,6 +46,7 @@ function PdfLogEntry({
<div <div
className={classNames('log-entry', customClass)} className={classNames('log-entry', customClass)}
aria-label={entryAriaLabel} aria-label={entryAriaLabel}
data-ruleid={ruleId}
> >
<PreviewLogEntryHeader <PreviewLogEntryHeader
level={level} level={level}

View file

@ -3,49 +3,43 @@ import ruleset from './HumanReadableLogsRules'
export default { export default {
parse(rawLog, options) { parse(rawLog, options) {
let parsedLogEntries const parsedLogEntries =
if (typeof rawLog === 'string') { typeof rawLog === 'string'
const latexLogParser = new LatexLogParser(rawLog, options) ? new LatexLogParser(rawLog, options).parse()
parsedLogEntries = latexLogParser.parse() : rawLog
} else {
parsedLogEntries = rawLog
}
const _getRule = function (logMessage) {
for (const rule of ruleset) {
if (rule.regexToMatch.test(logMessage)) {
return rule
}
}
}
const seenErrorTypes = {} // keep track of types of errors seen const seenErrorTypes = {} // keep track of types of errors seen
for (const entry of parsedLogEntries.all) { for (const entry of parsedLogEntries.all) {
const ruleDetails = _getRule(entry.message) const ruleDetails = ruleset.find(rule =>
rule.regexToMatch.test(entry.message)
)
if (ruleDetails != null) { if (ruleDetails) {
let type if (ruleDetails.ruleId) {
if (ruleDetails.ruleId != null) {
entry.ruleId = ruleDetails.ruleId entry.ruleId = ruleDetails.ruleId
} }
if (ruleDetails.newMessage != null) {
if (ruleDetails.newMessage) {
entry.message = entry.message.replace( entry.message = entry.message.replace(
ruleDetails.regexToMatch, ruleDetails.regexToMatch,
ruleDetails.newMessage ruleDetails.newMessage
) )
} }
if (ruleDetails.contentRegex) { if (ruleDetails.contentRegex) {
const match = entry.content.match(ruleDetails.contentRegex) const match = entry.content.match(ruleDetails.contentRegex)
if (match) { if (match) {
entry.contentDetails = match.slice(1) entry.contentDetails = match.slice(1)
} }
} }
if (entry.contentDetails && ruleDetails.improvedTitle) { if (entry.contentDetails && ruleDetails.improvedTitle) {
const message = ruleDetails.improvedTitle( const message = ruleDetails.improvedTitle(
entry.message, entry.message,
entry.contentDetails entry.contentDetails
) )
if (Array.isArray(message)) { if (Array.isArray(message)) {
entry.message = message[0] entry.message = message[0]
// removing the messageComponent, as the markup possible in it was causing crashes when // removing the messageComponent, as the markup possible in it was causing crashes when
@ -56,17 +50,19 @@ export default {
entry.message = message entry.message = message
} }
} }
// suppress any entries that are known to cascade from previous error types // suppress any entries that are known to cascade from previous error types
if (ruleDetails.cascadesFrom != null) { if (ruleDetails.cascadesFrom) {
for (type of ruleDetails.cascadesFrom) { for (const type of ruleDetails.cascadesFrom) {
if (seenErrorTypes[type]) { if (seenErrorTypes[type]) {
entry.suppressed = true entry.suppressed = true
} }
} }
} }
// record the types of errors seen // record the types of errors seen
if (ruleDetails.types != null) { if (ruleDetails.types) {
for (type of ruleDetails.types) { for (const type of ruleDetails.types) {
seenErrorTypes[type] = true seenErrorTypes[type] = true
} }
} }
@ -74,8 +70,7 @@ export default {
} }
// filter out the suppressed errors (from the array entries in parsedLogEntries) // filter out the suppressed errors (from the array entries in parsedLogEntries)
for (const key in parsedLogEntries) { for (const [key, errors] of Object.entries(parsedLogEntries)) {
const errors = parsedLogEntries[key]
if (typeof errors === 'object' && errors.length > 0) { if (typeof errors === 'object' && errors.length > 0) {
parsedLogEntries[key] = Array.from(errors).filter( parsedLogEntries[key] = Array.from(errors).filter(
err => !err.suppressed err => !err.suppressed