Skip to content

Commit

Permalink
If there is an error in transform, pass error to callback
Browse files Browse the repository at this point in the history
The error will in turn be emitted as an `error` event
  • Loading branch information
ZJONSSON committed Feb 18, 2018
1 parent 1fa58b5 commit 7ea27d3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ class ParquetTransformer extends stream.Transform {

_transform(row, encoding, callback) {
if (row) {
this.writer.appendRow(row).then(callback);
this.writer.appendRow(row)
.then(callback)
.catch(e => callback(e));
} else {
callback();
}
Expand Down
26 changes: 26 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,32 @@ describe('Parquet', function() {
istream.pipe(transform).pipe(ostream);
});

it('an error in transform is emitted in stream', async function() {
const opts = { useDataPageV2: true, compression: 'GZIP' };
let schema = mkTestSchema(opts);
let transform = new parquet.ParquetTransformer(schema, opts);
transform.writer.setMetadata("myuid", "420");
transform.writer.setMetadata("fnord", "dronf");

var ostream = fs.createWriteStream('fruits_stream.parquet');
let testRows = mkTestRows();
testRows[4].quantity = 'N/A';
let istream = objectStream.fromArray(testRows);
return new Promise( (resolve, reject) => {
setTimeout(() => resolve('no_error'),1000);
istream
.pipe(transform)
.on('error', reject)
.pipe(ostream)
.on('finish',resolve);
})
.then(
() => { throw new Error('Should emit error'); },
() => undefined
);

});

});

});
Expand Down

0 comments on commit 7ea27d3

Please sign in to comment.