Skip to content
This repository was archived by the owner on Feb 15, 2022. It is now read-only.

Commit b553044

Browse files
committed
Fixes the failure to emit errors correctly
This was exposed by: npm/npm#7763
1 parent 86b111e commit b553044

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ function cleanup (er) {
3939
}.bind(this))
4040
}
4141

42-
function cleanupSync (er) {
42+
function cleanupSync () {
4343
try {
4444
fs.unlinkSync(this.__atomicTmp)
4545
} finally {
46-
return fs.WriteStream.prototype.emit.call(this, 'error', er)
46+
return
4747
}
4848
}
4949

5050
// When we *would* emit 'close' or 'finish', instead do our stuff
5151
WriteStream.prototype.emit = function (ev) {
5252
if (ev === 'error')
53-
return cleanupSync(this)
53+
cleanupSync.call(this)
5454

5555
if (ev !== 'close' && ev !== 'finish')
5656
return fs.WriteStream.prototype.emit.apply(this, arguments)

test/toolong.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var path = require('path')
2+
var test = require('tap').test
3+
var writeStream = require('../index.js')
4+
5+
function repeat(times, string) {
6+
var output = ''
7+
for (var ii = 0; ii < times; ++ii) {
8+
output += string
9+
}
10+
return output
11+
}
12+
13+
var target = path.resolve(__dirname, repeat(1000,'test'))
14+
15+
test('name too long', function (t) {
16+
var stream = writeStream(target)
17+
stream.on('error', function (er) {
18+
t.is(er.code, 'ENAMETOOLONG', target.length + " character name results in ENAMETOOLONG")
19+
})
20+
stream.on('close', function () {
21+
t.end()
22+
})
23+
stream.end()
24+
})

0 commit comments

Comments
 (0)