Skip to content

Commit 873a955

Browse files
committed
make more robust
1 parent e224814 commit 873a955

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

scripts/collate-logs.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ const log_parsers = [
146146
type: 'callout',
147147
regex: /callout list item index: expected (?<expected>\d+), got (?<got>\d+)/
148148
},
149+
{
150+
type: 'existing',
151+
regex: /Page alias cannot reference an existing page: (?<coordinate>.*)\n\s*source: (?<source>.*)\n\s*existing page: (?<existing>.*)/m
152+
},
149153
]
150154

151155
const files = {}
@@ -163,26 +167,29 @@ var log_other = fs.createWriteStream("other.log", {flags:'w'});
163167

164168
var obj
165169
rl.on('line', (line) => {
166-
let ret
167170
if ((line.match(/^\{/) && line.match(/\}$/))) {
168171
obj = JSON.parse(line)
169172

173+
const filepath = obj?.file?.path
170174
// increment file counter
171-
files[obj.file.path] ||= 0
172-
files[obj.file.path] ++
175+
if (filepath) {
176+
files[filepath] ||= 0
177+
files[filepath] ++
178+
}
173179

174180
const msg = obj.msg
175181

176182
// for string messages, try each parser and *return early* if found
177183
if (typeof msg == 'string') {
178-
const prefix = path.basename(obj.source.url, '.git')
184+
const prefix = path.basename(obj?.source?.url || '', '.git')
179185

180186
flash(msg, prefix)
187+
let match
181188
for (const parser of log_parsers) {
182-
if (ret = parser.regex.exec(msg)) {
189+
if (match = parser.regex.exec(msg)) {
183190
errors[parser.type]++;
184191
obj.type = parser.type
185-
if (ret.groups) { obj.details = ret.groups }
192+
if (match.groups) { obj.details = {... match.groups} }
186193
log_main.write(JSON.stringify(obj) + "\n")
187194
return
188195
}

0 commit comments

Comments
 (0)