Skip to content

Commit

Permalink
Merge pull request #1 from voldern/records-in-error
Browse files Browse the repository at this point in the history
Add failed records to error objects
  • Loading branch information
Espen Volden committed Nov 16, 2015
2 parents d501ed5 + d25a409 commit eabad1e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.1.0] - 2015-11-16
### Changed
- Add property `records` to error events which contains the records
that couldn't be written

## [0.0.4] - 2015-10-28
### Added
- Keywords to package.json
Expand Down
2 changes: 1 addition & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ A simple wrapper around Elasticsearch for bulk writing items
| --- | --- | --- | --- |
| client | <code>Elasticsearch.Client</code> | | Elasticsearch client |
| options | <code>Object</code> | | Options |
| [options.highWaterMark] | <code>Number</code> | <code>16</code> | Number of items to buffer before writing. Also the size of the underlying stream buffer. |
| [options.highWaterMark] | <code>number</code> | <code>16</code> | Number of items to buffer before writing. Also the size of the underlying stream buffer. |
| [options.logger] | <code>Object</code> | | Instance of a logger like bunyan or winston |

7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ ElasticsearchBulkIndexWritable.prototype._flush = function _flush(callback) {

this.client.bulk({ body: records }, function bulkCallback(err, data) {
if (err) {
err.records = records;

return callback(err);
}

Expand All @@ -93,7 +95,10 @@ ElasticsearchBulkIndexWritable.prototype._flush = function _flush(callback) {
errors.forEach(this.logger.error.bind(this.logger));
}

return callback(new Error(errors));
var error = new Error(errors);
error.records = records;

return callback(error);
}

if (this.logger) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elasticsearch-bulk-index-stream",
"version": "0.0.4",
"version": "0.1.0",
"description": "A writable stream for bulk indexing records in Elasticsearch",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/elasticsearch-bulk-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ describe('ElastisearchBulkIndexWritable', function() {
});

it('should trigger error on elasticsearch error', function(done) {
this.client.bulk.yields('Fail');
this.client.bulk.yields(new Error('Fail'));

this.stream.on('error', function(error) {
expect(error).to.eq('Fail');
expect(error.message).to.eq('Fail');

done();
});
Expand Down

0 comments on commit eabad1e

Please sign in to comment.