diff --git a/papaparse.js b/papaparse.js index 8b2b192..589a80d 100755 --- a/papaparse.js +++ b/papaparse.js @@ -637,7 +637,7 @@ this._chunkError = function(errorMessage) { var errorText = xhr.statusText || errorMessage; - this._sendError(errorText); + this._sendError(new Error(errorText)); } function getFileSize(xhr) @@ -712,7 +712,7 @@ this._chunkError = function() { - this._sendError(reader.error.message); + this._sendError(reader.error); } } @@ -796,7 +796,7 @@ this._streamError = bindFunction(function(error) { this._streamCleanUp(); - this._sendError(error.message); + this._sendError(error); }, this); this._streamEnd = bindFunction(function() diff --git a/tests/node-tests.js b/tests/node-tests.js index 30e2693..3cfa272 100644 --- a/tests/node-tests.js +++ b/tests/node-tests.js @@ -92,5 +92,44 @@ describe('PapaParse', function() { } }); }); + + it('handles errors in beforeFirstChunk', function(done) { + var expectedError = new Error('test'); + Papa.parse(fs.createReadStream(__dirname + '/long-sample.csv', 'utf8'), { + beforeFirstChunk: function() { + throw expectedError; + }, + error: function(err) { + assert.deepEqual(err, expectedError); + done(); + } + }); + }); + + it('handles errors in chunk', function(done) { + var expectedError = new Error('test'); + Papa.parse(fs.createReadStream(__dirname + '/long-sample.csv', 'utf8'), { + chunk: function() { + throw expectedError; + }, + error: function(err) { + assert.deepEqual(err, expectedError); + done(); + } + }); + }); + + it('handles errors in step', function(done) { + var expectedError = new Error('test'); + Papa.parse(fs.createReadStream(__dirname + '/long-sample.csv', 'utf8'), { + step: function() { + throw expectedError; + }, + error: function(err) { + assert.deepEqual(err, expectedError); + done(); + } + }); + }); }); });