2016-06-16 06:14:45 -04:00
|
|
|
define [
|
|
|
|
"libs/latex-log-parser"
|
2016-06-16 10:29:00 -04:00
|
|
|
"ide/human-readable-logs/HumanReadableLogsRules"
|
|
|
|
], (LogParser, ruleset) ->
|
2016-06-16 06:14:45 -04:00
|
|
|
parse : (rawLog, options) ->
|
2016-07-27 11:51:13 -04:00
|
|
|
if typeof rawLog is 'string'
|
|
|
|
parsedLogEntries = LogParser.parse(rawLog, options)
|
|
|
|
else
|
|
|
|
parsedLogEntries = rawLog
|
2016-06-16 10:29:00 -04:00
|
|
|
|
2016-06-17 06:42:32 -04:00
|
|
|
_getRule = (logMessage) ->
|
|
|
|
return rule for rule in ruleset when rule.regexToMatch.test logMessage
|
2016-06-16 10:53:39 -04:00
|
|
|
|
2016-08-18 08:21:27 -04:00
|
|
|
seenErrorTypes = {} # keep track of types of errors seen
|
|
|
|
|
2016-06-16 10:53:39 -04:00
|
|
|
for entry in parsedLogEntries.all
|
2016-06-21 07:07:47 -04:00
|
|
|
ruleDetails = _getRule entry.message
|
2016-06-16 10:29:00 -04:00
|
|
|
|
2016-06-21 07:07:47 -04:00
|
|
|
if (ruleDetails?)
|
2016-07-27 11:52:36 -04:00
|
|
|
if ruleDetails.ruleId?
|
|
|
|
entry.ruleId = ruleDetails.ruleId
|
|
|
|
else if ruleDetails.regexToMatch?
|
|
|
|
entry.ruleId = 'hint_' + ruleDetails.regexToMatch.toString().replace(/\s/g, '_').slice(1, -1)
|
|
|
|
if ruleDetails.newMessage?
|
|
|
|
entry.message = entry.message.replace ruleDetails.regexToMatch, ruleDetails.newMessage
|
2016-08-18 08:21:27 -04:00
|
|
|
# suppress any entries that are known to cascade from previous error types
|
|
|
|
if ruleDetails.cascadesFrom?
|
|
|
|
for type in ruleDetails.cascadesFrom
|
|
|
|
entry.suppressed = true if seenErrorTypes[type]
|
|
|
|
# record the types of errors seen
|
|
|
|
if ruleDetails.types?
|
|
|
|
for type in ruleDetails.types
|
|
|
|
seenErrorTypes[type] = true
|
2016-06-30 06:30:43 -04:00
|
|
|
|
2016-06-21 07:07:47 -04:00
|
|
|
entry.humanReadableHint = ruleDetails.humanReadableHint if ruleDetails.humanReadableHint?
|
|
|
|
entry.extraInfoURL = ruleDetails.extraInfoURL if ruleDetails.extraInfoURL?
|
2016-08-18 08:21:27 -04:00
|
|
|
|
|
|
|
# filter out the suppressed errors (from the array entries in parsedLogEntries)
|
|
|
|
for key, errors of parsedLogEntries when typeof errors is 'object' and errors.length > 0
|
|
|
|
parsedLogEntries[key] = (err for err in errors when not err.suppressed)
|
|
|
|
|
2016-06-16 06:14:45 -04:00
|
|
|
return parsedLogEntries
|