Skip to content

Commit 17bc4c1

Browse files
committed
fix: pass parse errors to transform callback instead of throwing
1 parent 814356e commit 17bc4c1

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎commit-stream.js‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ export default function commitStream (ghUser, ghProject) {
4646
return new Transform({
4747
objectMode: true,
4848
transform (line, _, callback) {
49-
emit(this, addLine(line))
50-
callback()
49+
try {
50+
emit(this, addLine(line))
51+
callback()
52+
} catch (err) {
53+
callback(/** @type {Error} */ (err))
54+
}
5155
},
5256
flush (callback) {
5357
emit(this, commit)
@@ -73,7 +77,7 @@ export default function commitStream (ghUser, ghProject) {
7377
let m
7478

7579
if (!commit) {
76-
throw new Error('Something unexpected occurred')
80+
throw new Error(`Unexpected line before first "commit" header: ${line}`)
7781
}
7882

7983
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)