2021-09-28 05:32:52 -04:00
|
|
|
import LatexLogParser from '../log-parser/latex-log-parser'
|
2020-05-19 05:02:56 -04:00
|
|
|
import ruleset from './HumanReadableLogsRules'
|
|
|
|
|
|
|
|
export default {
|
2018-11-05 05:06:39 -05:00
|
|
|
parse(rawLog, options) {
|
2024-04-30 05:33:45 -04:00
|
|
|
const parsedLogEntries =
|
|
|
|
typeof rawLog === 'string'
|
|
|
|
? new LatexLogParser(rawLog, options).parse()
|
|
|
|
: rawLog
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
const seenErrorTypes = {} // keep track of types of errors seen
|
|
|
|
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const entry of parsedLogEntries.all) {
|
2024-04-30 05:33:45 -04:00
|
|
|
const ruleDetails = ruleset.find(rule =>
|
|
|
|
rule.regexToMatch.test(entry.message)
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2024-04-30 05:33:45 -04:00
|
|
|
if (ruleDetails) {
|
|
|
|
if (ruleDetails.ruleId) {
|
2018-11-05 05:06:39 -05:00
|
|
|
entry.ruleId = ruleDetails.ruleId
|
|
|
|
}
|
2024-04-30 05:33:45 -04:00
|
|
|
|
|
|
|
if (ruleDetails.newMessage) {
|
2018-11-05 05:06:39 -05:00
|
|
|
entry.message = entry.message.replace(
|
|
|
|
ruleDetails.regexToMatch,
|
|
|
|
ruleDetails.newMessage
|
|
|
|
)
|
|
|
|
}
|
2024-04-30 05:33:45 -04:00
|
|
|
|
2023-02-20 08:45:22 -05:00
|
|
|
if (ruleDetails.contentRegex) {
|
|
|
|
const match = entry.content.match(ruleDetails.contentRegex)
|
|
|
|
if (match) {
|
|
|
|
entry.contentDetails = match.slice(1)
|
|
|
|
}
|
|
|
|
}
|
2024-04-30 05:33:45 -04:00
|
|
|
|
2023-02-20 08:45:22 -05:00
|
|
|
if (entry.contentDetails && ruleDetails.improvedTitle) {
|
2023-09-11 05:56:43 -04:00
|
|
|
const message = ruleDetails.improvedTitle(
|
2023-02-20 08:45:22 -05:00
|
|
|
entry.message,
|
|
|
|
entry.contentDetails
|
|
|
|
)
|
2024-04-30 05:33:45 -04:00
|
|
|
|
2023-09-11 05:56:43 -04:00
|
|
|
if (Array.isArray(message)) {
|
|
|
|
entry.message = message[0]
|
2023-09-29 09:56:14 -04:00
|
|
|
// removing the messageComponent, as the markup possible in it was causing crashes when
|
|
|
|
// attempting to broadcast it in the detach-context (cant structuredClone an html node)
|
|
|
|
// see https://github.com/overleaf/internal/discussions/15031 for context
|
|
|
|
// entry.messageComponent = message[1]
|
2023-09-11 05:56:43 -04:00
|
|
|
} else {
|
|
|
|
entry.message = message
|
|
|
|
}
|
2023-02-20 08:45:22 -05:00
|
|
|
}
|
2024-04-30 05:33:45 -04:00
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
// suppress any entries that are known to cascade from previous error types
|
2024-04-30 05:33:45 -04:00
|
|
|
if (ruleDetails.cascadesFrom) {
|
|
|
|
for (const type of ruleDetails.cascadesFrom) {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (seenErrorTypes[type]) {
|
|
|
|
entry.suppressed = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-30 05:33:45 -04:00
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
// record the types of errors seen
|
2024-04-30 05:33:45 -04:00
|
|
|
if (ruleDetails.types) {
|
|
|
|
for (const type of ruleDetails.types) {
|
2018-11-05 05:06:39 -05:00
|
|
|
seenErrorTypes[type] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// filter out the suppressed errors (from the array entries in parsedLogEntries)
|
2024-04-30 05:33:45 -04:00
|
|
|
for (const [key, errors] of Object.entries(parsedLogEntries)) {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (typeof errors === 'object' && errors.length > 0) {
|
|
|
|
parsedLogEntries[key] = Array.from(errors).filter(
|
|
|
|
err => !err.suppressed
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsedLogEntries
|
2021-04-27 03:52:58 -04:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|