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
className={classNames('log-entry', customClass)}
aria-label={entryAriaLabel}
data-ruleid={ruleId}
>
<PreviewLogEntryHeader
level={level}

View file

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