Skip to content

Commit eabad1e

Browse files
author
Espen Volden
committed
Merge pull request #1 from voldern/records-in-error
Add failed records to error objects
2 parents d501ed5 + d25a409 commit eabad1e

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [0.1.0] - 2015-11-16
6+
### Changed
7+
- Add property `records` to error events which contains the records
8+
that couldn't be written
9+
510
## [0.0.4] - 2015-10-28
611
### Added
712
- Keywords to package.json

api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ A simple wrapper around Elasticsearch for bulk writing items
88
| --- | --- | --- | --- |
99
| client | <code>Elasticsearch.Client</code> | | Elasticsearch client |
1010
| options | <code>Object</code> | | Options |
11-
| [options.highWaterMark] | <code>Number</code> | <code>16</code> | Number of items to buffer before writing. Also the size of the underlying stream buffer. |
11+
| [options.highWaterMark] | <code>number</code> | <code>16</code> | Number of items to buffer before writing. Also the size of the underlying stream buffer. |
1212
| [options.logger] | <code>Object</code> | | Instance of a logger like bunyan or winston |
1313

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ ElasticsearchBulkIndexWritable.prototype._flush = function _flush(callback) {
7979

8080
this.client.bulk({ body: records }, function bulkCallback(err, data) {
8181
if (err) {
82+
err.records = records;
83+
8284
return callback(err);
8385
}
8486

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

96-
return callback(new Error(errors));
98+
var error = new Error(errors);
99+
error.records = records;
100+
101+
return callback(error);
97102
}
98103

99104
if (this.logger) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "elasticsearch-bulk-index-stream",
3-
"version": "0.0.4",
3+
"version": "0.1.0",
44
"description": "A writable stream for bulk indexing records in Elasticsearch",
55
"main": "index.js",
66
"scripts": {

test/elasticsearch-bulk-stream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ describe('ElastisearchBulkIndexWritable', function() {
107107
});
108108

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

112112
this.stream.on('error', function(error) {
113-
expect(error).to.eq('Fail');
113+
expect(error.message).to.eq('Fail');
114114

115115
done();
116116
});

0 commit comments

Comments
 (0)