diff --git a/grep-mtime-sorter.mjs b/grep-mtime-sorter.mjs index 252eded..aeec592 100755 --- a/grep-mtime-sorter.mjs +++ b/grep-mtime-sorter.mjs @@ -10,6 +10,7 @@ and has only been superficially tested. It should be considered experimental and import fs from 'node:fs'; import { stat } from 'node:fs/promises'; +import { inspect } from 'node:util'; const lineRe = /^\x1b\[35m\x1b\[K(.*?)\x1b/; @@ -35,7 +36,7 @@ async function getMtime(line) { return 0; } } else { - throw new Error('Malformed input: ANSI prefix not found'); + throw new Error(`Malformed input: ANSI prefix not found for line ${inspect(line)}`); } } @@ -47,7 +48,7 @@ async function main() { process.stdin.on('end', () => { resolve(data); }); }); - const lines = input.split(/(?<=\n)/); + const lines = input.split(/(?<=\n)/).filter(line => line.trim().length > 0); const pairs = await Promise.all( lines.map(async (line, index) => {