Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit b78841e

Browse files
committed
Pass output stream errors through with error (also includes test)
1 parent 59df7f8 commit b78841e

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/processor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,9 @@ module.exports = function(proto) {
490490

491491
outputStream.target.on('error', function(err) {
492492
self.logger.debug('Output stream error, killing ffmpgeg process');
493-
emitEnd(new Error('Output stream error: ' + err.message), stdoutRing.get(), stderrRing.get());
493+
var reportingErr = new Error('Output stream error: ' + err.message);
494+
reportingErr.outputStreamError = err;
495+
emitEnd(reportingErr, stdoutRing.get(), stderrRing.get());
494496
ffmpegProc.kill();
495497
});
496498
}

test/processor.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,44 @@ describe('Processor', function() {
953953
new FfmpegCommand().writeToStream({end: true});
954954
}).should.throw(/PassThrough stream is not supported on node v0.8/);
955955
});
956+
957+
it('should pass output stream errors through to error handler', function(done) {
958+
959+
const writeError = new Error('Write Error')
960+
const outstream = new (require('stream').Writable)({
961+
write(chunk, encoding, callback) {
962+
callback(writeError)
963+
}
964+
})
965+
966+
const command = this.getCommand({ source: this.testfile, logger: testhelper.logger })
967+
968+
let startCalled = false
969+
const self = this
970+
971+
command
972+
.usingPreset('divx')
973+
.on('start', function() {
974+
startCalled = true
975+
command.ffmpegProc.on('exit', function() {
976+
done()
977+
})
978+
})
979+
.on('error', function(err, stdout, stderr) {
980+
self.saveOutput(stdout, stderr)
981+
startCalled.should.be.true()
982+
assert.ok(err)
983+
err.message.indexOf('Output stream error: ').should.equal(0)
984+
assert.strictEqual(err.outputStreamError, writeError)
985+
})
986+
.on('end', function(stdout, stderr) {
987+
console.log('end was called, expected a error')
988+
testhelper.logOutput(stdout, stderr)
989+
assert.ok(false)
990+
done()
991+
})
992+
.writeToStream(outstream)
993+
})
956994
});
957995

958996
describe('Outputs', function() {

0 commit comments

Comments
 (0)