Skip to content

Commit f0d2a32

Browse files
authored
fix: pass parse errors to transform callback instead of throwing (#38)
1 parent 814356e commit f0d2a32

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎commit-stream.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ export default function commitStream (ghUser, ghProject) {
4646
return new Transform({
4747
objectMode: true,
4848
transform (line, _, callback) {
49-
emit(this, addLine(line))
49+
let done
50+
try {
51+
done = addLine(line)
52+
} catch (err) {
53+
return callback(/** @type {Error} */ (err))
54+
}
55+
emit(this, done)
5056
callback()
5157
},
5258
flush (callback) {
@@ -73,7 +79,7 @@ export default function commitStream (ghUser, ghProject) {
7379
let m
7480

7581
if (!commit) {
76-
throw new Error('Something unexpected occurred')
82+
throw new Error(`Unexpected line before first "commit" header: ${line}`)
7783
}
7884

7985
if ((m = line.match(/^CommitDate:\s+(.*)$/)) !== null) {

‎test.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,17 @@ test('cve id with 4 or more sequence digits', async () => {
233233
const commits = await toCommits(ids.flatMap(log))
234234
assert.deepStrictEqual(commits.map((c) => c.cveId), ids)
235235
})
236+
237+
test('line before first commit header rejects pipeline', async () => {
238+
await assert.rejects(toCommits(['garbage']), {
239+
message: 'Unexpected line before first "commit" header: garbage'
240+
})
241+
})
242+
243+
test('line before first commit header emits error on write', async () => {
244+
const stream = commitStream()
245+
const error = once(stream, 'error')
246+
stream.write('garbage')
247+
const [err] = await error
248+
assert.strictEqual(err.message, 'Unexpected line before first "commit" header: garbage')
249+
})

‎types/commit-stream.d.ts.map‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)