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

Commit 59df7f8

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

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/processor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ module.exports = function(proto) {
444444
// Pipe input stream if any
445445
if (inputStream) {
446446
inputStream.source.on('error', function(err) {
447-
emitEnd(new Error('Input stream error: ' + err.message));
447+
var reportingErr = new Error('Input stream error: ' + err.message);
448+
reportingErr.inputStreamError = err;
449+
emitEnd(reportingErr);
448450
ffmpegProc.kill();
449451
});
450452

test/processor.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,48 @@ describe('Processor', function() {
770770
})
771771
.saveToFile(testFile);
772772
});
773+
774+
it('should pass input stream errors through to error handler', function(done) {
775+
var testFile = path.join(__dirname, 'assets', 'testConvertFromStream.avi')
776+
777+
const readError = new Error('Read Error')
778+
const instream = new (require('stream').Readable)({
779+
read() {
780+
process.nextTick(() => this.emit('error', readError))
781+
}
782+
})
783+
784+
const command = this.getCommand({ source: instream, logger: testhelper.logger })
785+
786+
let startCalled = false
787+
const self = this
788+
789+
command
790+
.usingPreset('divx')
791+
.on('start', function() {
792+
startCalled = true
793+
command.ffmpegProc.on('exit', function() {
794+
fs.exists(testFile, (exists) => {
795+
exists.should.be.false()
796+
done()
797+
})
798+
})
799+
})
800+
.on('error', function(err, stdout, stderr) {
801+
self.saveOutput(stdout, stderr)
802+
startCalled.should.be.true()
803+
assert.ok(err)
804+
err.message.indexOf('Input stream error: ').should.equal(0)
805+
assert.strictEqual(err.inputStreamError, readError)
806+
})
807+
.on('end', function(stdout, stderr) {
808+
testhelper.logOutput(stdout, stderr)
809+
console.log('end was called, expected a error')
810+
assert.ok(false)
811+
done()
812+
})
813+
.saveToFile(testFile)
814+
})
773815
});
774816

775817
describe('mergeToFile', function() {

0 commit comments

Comments
 (0)