Browse Source

Pass full error object on stream errors

Fixes #472
pull/481/head
Gabe Gorelick 7 years ago committed by Sergi Almacellas Abellana
parent
commit
90da3be5fb
  1. 6
      papaparse.js
  2. 39
      tests/node-tests.js

6
papaparse.js

@ -637,7 +637,7 @@ @@ -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 @@ @@ -712,7 +712,7 @@
this._chunkError = function()
{
this._sendError(reader.error.message);
this._sendError(reader.error);
}
}
@ -796,7 +796,7 @@ @@ -796,7 +796,7 @@
this._streamError = bindFunction(function(error)
{
this._streamCleanUp();
this._sendError(error.message);
this._sendError(error);
}, this);
this._streamEnd = bindFunction(function()

39
tests/node-tests.js

@ -92,5 +92,44 @@ describe('PapaParse', function() { @@ -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();
}
});
});
});
});

Loading…
Cancel
Save