Skip to content

Commit f031542

Browse files
committed
fix(csv-generate): catch invalid value error
1 parent 8a5eb7d commit f031542

File tree

11 files changed

+64
-37
lines changed

11 files changed

+64
-37
lines changed

packages/csv-generate/dist/cjs/index.cjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ const read = (options, state, size, push, close) => {
138138
// Create the record
139139
let record = [];
140140
let recordLength;
141-
options.columns.forEach((fn) => {
141+
for(const fn of options.columns){
142142
const result = fn({options: options, state: state});
143143
const type = typeof result;
144144
if(result !== null && type !== 'string' && type !== 'number'){
145-
throw Error([
145+
return Error([
146146
'INVALID_VALUE:',
147147
'values returned by column function must be',
148148
'a string, a number or null,',
149149
`got ${JSON.stringify(result)}`
150150
].join(' '));
151151
}
152152
record.push(result);
153-
});
153+
}
154154
// Obtain record length
155155
if(options.objectMode){
156156
recordLength = 0;
@@ -203,11 +203,14 @@ Generator.prototype.end = function(){
203203
// Put new data into the read queue.
204204
Generator.prototype._read = function(size){
205205
const self = this;
206-
read(this.options, this.state, size, function(chunk) {
206+
const err = read(this.options, this.state, size, function(chunk) {
207207
self.__push(chunk);
208208
}, function(){
209209
self.push(null);
210210
});
211+
if(err){
212+
this.destroy(err);
213+
}
211214
};
212215
// Put new data into the read queue.
213216
Generator.prototype.__push = function(record){

packages/csv-generate/dist/cjs/sync.cjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,19 @@ const read = (options, state, size, push, close) => {
138138
// Create the record
139139
let record = [];
140140
let recordLength;
141-
options.columns.forEach((fn) => {
141+
for(const fn of options.columns){
142142
const result = fn({options: options, state: state});
143143
const type = typeof result;
144144
if(result !== null && type !== 'string' && type !== 'number'){
145-
throw Error([
145+
return Error([
146146
'INVALID_VALUE:',
147147
'values returned by column function must be',
148148
'a string, a number or null,',
149149
`got ${JSON.stringify(result)}`
150150
].join(' '));
151151
}
152152
record.push(result);
153-
});
153+
}
154154
// Obtain record length
155155
if(options.objectMode){
156156
recordLength = 0;
@@ -203,11 +203,14 @@ Generator.prototype.end = function(){
203203
// Put new data into the read queue.
204204
Generator.prototype._read = function(size){
205205
const self = this;
206-
read(this.options, this.state, size, function(chunk) {
206+
const err = read(this.options, this.state, size, function(chunk) {
207207
self.__push(chunk);
208208
}, function(){
209209
self.push(null);
210210
});
211+
if(err){
212+
this.destroy(err);
213+
}
211214
};
212215
// Put new data into the read queue.
213216
Generator.prototype.__push = function(record){

packages/csv-generate/dist/esm/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5164,19 +5164,19 @@ const read = (options, state, size, push, close) => {
51645164
// Create the record
51655165
let record = [];
51665166
let recordLength;
5167-
options.columns.forEach((fn) => {
5167+
for(const fn of options.columns){
51685168
const result = fn({options: options, state: state});
51695169
const type = typeof result;
51705170
if(result !== null && type !== 'string' && type !== 'number'){
5171-
throw Error([
5171+
return Error([
51725172
'INVALID_VALUE:',
51735173
'values returned by column function must be',
51745174
'a string, a number or null,',
51755175
`got ${JSON.stringify(result)}`
51765176
].join(' '));
51775177
}
51785178
record.push(result);
5179-
});
5179+
}
51805180
// Obtain record length
51815181
if(options.objectMode){
51825182
recordLength = 0;
@@ -5229,11 +5229,14 @@ Generator.prototype.end = function(){
52295229
// Put new data into the read queue.
52305230
Generator.prototype._read = function(size){
52315231
const self = this;
5232-
read(this.options, this.state, size, function(chunk) {
5232+
const err = read(this.options, this.state, size, function(chunk) {
52335233
self.__push(chunk);
52345234
}, function(){
52355235
self.push(null);
52365236
});
5237+
if(err){
5238+
this.destroy(err);
5239+
}
52375240
};
52385241
// Put new data into the read queue.
52395242
Generator.prototype.__push = function(record){

packages/csv-generate/dist/esm/sync.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5164,19 +5164,19 @@ const read = (options, state, size, push, close) => {
51645164
// Create the record
51655165
let record = [];
51665166
let recordLength;
5167-
options.columns.forEach((fn) => {
5167+
for(const fn of options.columns){
51685168
const result = fn({options: options, state: state});
51695169
const type = typeof result;
51705170
if(result !== null && type !== 'string' && type !== 'number'){
5171-
throw Error([
5171+
return Error([
51725172
'INVALID_VALUE:',
51735173
'values returned by column function must be',
51745174
'a string, a number or null,',
51755175
`got ${JSON.stringify(result)}`
51765176
].join(' '));
51775177
}
51785178
record.push(result);
5179-
});
5179+
}
51805180
// Obtain record length
51815181
if(options.objectMode){
51825182
recordLength = 0;
@@ -5229,11 +5229,14 @@ Generator.prototype.end = function(){
52295229
// Put new data into the read queue.
52305230
Generator.prototype._read = function(size){
52315231
const self = this;
5232-
read(this.options, this.state, size, function(chunk) {
5232+
const err = read(this.options, this.state, size, function(chunk) {
52335233
self.__push(chunk);
52345234
}, function(){
52355235
self.push(null);
52365236
});
5237+
if(err){
5238+
this.destroy(err);
5239+
}
52375240
};
52385241
// Put new data into the read queue.
52395242
Generator.prototype.__push = function(record){

packages/csv-generate/dist/iife/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,19 +5167,19 @@ var csv_generate = (function (exports) {
51675167
// Create the record
51685168
let record = [];
51695169
let recordLength;
5170-
options.columns.forEach((fn) => {
5170+
for(const fn of options.columns){
51715171
const result = fn({options: options, state: state});
51725172
const type = typeof result;
51735173
if(result !== null && type !== 'string' && type !== 'number'){
5174-
throw Error([
5174+
return Error([
51755175
'INVALID_VALUE:',
51765176
'values returned by column function must be',
51775177
'a string, a number or null,',
51785178
`got ${JSON.stringify(result)}`
51795179
].join(' '));
51805180
}
51815181
record.push(result);
5182-
});
5182+
}
51835183
// Obtain record length
51845184
if(options.objectMode){
51855185
recordLength = 0;
@@ -5232,11 +5232,14 @@ var csv_generate = (function (exports) {
52325232
// Put new data into the read queue.
52335233
Generator.prototype._read = function(size){
52345234
const self = this;
5235-
read(this.options, this.state, size, function(chunk) {
5235+
const err = read(this.options, this.state, size, function(chunk) {
52365236
self.__push(chunk);
52375237
}, function(){
52385238
self.push(null);
52395239
});
5240+
if(err){
5241+
this.destroy(err);
5242+
}
52405243
};
52415244
// Put new data into the read queue.
52425245
Generator.prototype.__push = function(record){

packages/csv-generate/dist/iife/sync.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,19 +5167,19 @@ var csv_generate_sync = (function (exports) {
51675167
// Create the record
51685168
let record = [];
51695169
let recordLength;
5170-
options.columns.forEach((fn) => {
5170+
for(const fn of options.columns){
51715171
const result = fn({options: options, state: state});
51725172
const type = typeof result;
51735173
if(result !== null && type !== 'string' && type !== 'number'){
5174-
throw Error([
5174+
return Error([
51755175
'INVALID_VALUE:',
51765176
'values returned by column function must be',
51775177
'a string, a number or null,',
51785178
`got ${JSON.stringify(result)}`
51795179
].join(' '));
51805180
}
51815181
record.push(result);
5182-
});
5182+
}
51835183
// Obtain record length
51845184
if(options.objectMode){
51855185
recordLength = 0;
@@ -5232,11 +5232,14 @@ var csv_generate_sync = (function (exports) {
52325232
// Put new data into the read queue.
52335233
Generator.prototype._read = function(size){
52345234
const self = this;
5235-
read(this.options, this.state, size, function(chunk) {
5235+
const err = read(this.options, this.state, size, function(chunk) {
52365236
self.__push(chunk);
52375237
}, function(){
52385238
self.push(null);
52395239
});
5240+
if(err){
5241+
this.destroy(err);
5242+
}
52405243
};
52415244
// Put new data into the read queue.
52425245
Generator.prototype.__push = function(record){

packages/csv-generate/dist/umd/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5170,19 +5170,19 @@
51705170
// Create the record
51715171
let record = [];
51725172
let recordLength;
5173-
options.columns.forEach((fn) => {
5173+
for(const fn of options.columns){
51745174
const result = fn({options: options, state: state});
51755175
const type = typeof result;
51765176
if(result !== null && type !== 'string' && type !== 'number'){
5177-
throw Error([
5177+
return Error([
51785178
'INVALID_VALUE:',
51795179
'values returned by column function must be',
51805180
'a string, a number or null,',
51815181
`got ${JSON.stringify(result)}`
51825182
].join(' '));
51835183
}
51845184
record.push(result);
5185-
});
5185+
}
51865186
// Obtain record length
51875187
if(options.objectMode){
51885188
recordLength = 0;
@@ -5235,11 +5235,14 @@
52355235
// Put new data into the read queue.
52365236
Generator.prototype._read = function(size){
52375237
const self = this;
5238-
read(this.options, this.state, size, function(chunk) {
5238+
const err = read(this.options, this.state, size, function(chunk) {
52395239
self.__push(chunk);
52405240
}, function(){
52415241
self.push(null);
52425242
});
5243+
if(err){
5244+
this.destroy(err);
5245+
}
52435246
};
52445247
// Put new data into the read queue.
52455248
Generator.prototype.__push = function(record){

packages/csv-generate/dist/umd/sync.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5170,19 +5170,19 @@
51705170
// Create the record
51715171
let record = [];
51725172
let recordLength;
5173-
options.columns.forEach((fn) => {
5173+
for(const fn of options.columns){
51745174
const result = fn({options: options, state: state});
51755175
const type = typeof result;
51765176
if(result !== null && type !== 'string' && type !== 'number'){
5177-
throw Error([
5177+
return Error([
51785178
'INVALID_VALUE:',
51795179
'values returned by column function must be',
51805180
'a string, a number or null,',
51815181
`got ${JSON.stringify(result)}`
51825182
].join(' '));
51835183
}
51845184
record.push(result);
5185-
});
5185+
}
51865186
// Obtain record length
51875187
if(options.objectMode){
51885188
recordLength = 0;
@@ -5235,11 +5235,14 @@
52355235
// Put new data into the read queue.
52365236
Generator.prototype._read = function(size){
52375237
const self = this;
5238-
read(this.options, this.state, size, function(chunk) {
5238+
const err = read(this.options, this.state, size, function(chunk) {
52395239
self.__push(chunk);
52405240
}, function(){
52415241
self.push(null);
52425242
});
5243+
if(err){
5244+
this.destroy(err);
5245+
}
52435246
};
52445247
// Put new data into the read queue.
52455248
Generator.prototype.__push = function(record){

packages/csv-generate/lib/api/read.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ const read = (options, state, size, push, close) => {
2929
// Create the record
3030
let record = [];
3131
let recordLength;
32-
options.columns.forEach((fn) => {
32+
for(const fn of options.columns){
3333
const result = fn({options: options, state: state});
3434
const type = typeof result;
3535
if(result !== null && type !== 'string' && type !== 'number'){
36-
throw Error([
36+
return Error([
3737
'INVALID_VALUE:',
3838
'values returned by column function must be',
3939
'a string, a number or null,',
4040
`got ${JSON.stringify(result)}`
4141
].join(' '));
4242
}
4343
record.push(result);
44-
});
44+
}
4545
// Obtain record length
4646
if(options.objectMode){
4747
recordLength = 0;

packages/csv-generate/lib/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ Generator.prototype.end = function(){
2626
// Put new data into the read queue.
2727
Generator.prototype._read = function(size){
2828
const self = this;
29-
read(this.options, this.state, size, function(chunk) {
29+
const err = read(this.options, this.state, size, function(chunk) {
3030
self.__push(chunk);
3131
}, function(){
3232
self.push(null);
3333
});
34+
if(err){
35+
this.destroy(err);
36+
}
3437
};
3538
// Put new data into the read queue.
3639
Generator.prototype.__push = function(record){

packages/csv-generate/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"preversion": "npm run build && git add dist",
7878
"pretest": "npm run build",
7979
"test": "mocha 'test/**/*.{coffee,ts}'",
80-
"test:legacy": "mocha --loader=./test/loaders/legacy/all.js 'test/**/*.{coffee,ts}'"
80+
"test:legacy": "mocha --loader=./test/loaders/legacy/all.js 'test/**/*.{coffee,ts}' --ignore test/api.web_stream.coffee"
8181
},
8282
"type": "module",
8383
"types": "dist/esm/index.d.ts",

0 commit comments

Comments
 (0)