Skip to content

Commit

Permalink
fix: don't throw in _transform of BulkLoad (#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
everhardt authored Aug 7, 2024
1 parent 42617e4 commit afd3b54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/bulk-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,13 @@ class RowTransform extends Transform {
this.push(textPointerAndTimestampBuffer);
}

this.push(c.type.generateParameterLength(parameter, this.mainOptions));
for (const chunk of c.type.generateParameterData(parameter, this.mainOptions)) {
this.push(chunk);
try {
this.push(c.type.generateParameterLength(parameter, this.mainOptions));
for (const chunk of c.type.generateParameterData(parameter, this.mainOptions)) {
this.push(chunk);
}
} catch (error: any) {
return callback(error);
}
}

Expand Down
24 changes: 24 additions & 0 deletions test/integration/bulk-load-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1563,4 +1563,28 @@ describe('BulkLoad', function() {
}
});
});

it('should not throw in _transform function', (done) => {
const bulkLoad = connection.newBulkLoad(
'#tmpTestTable',
(err, rowCount) => {
assert.instanceOf(err, RangeError);
assert.strictEqual(/** @type {RangeError} */(err).message, 'The value of "value" is out of range. It must be >= 0 and <= 4294967295. Received 3_.40_282_346_638_528_86e_+42');
assert.strictEqual(rowCount, 0);
done();
});

bulkLoad.addColumn('value', TYPES.Decimal, { precision: 7, scale: 4, nullable: true });

const request = new Request(bulkLoad.getTableCreationSql(), (err) => {
if (err) {
return done(err);
}

connection.execBulkLoad(bulkLoad, [[-3.4028234663852886e+38]]);
});

connection.execSqlBatch(request);

});
});

0 comments on commit afd3b54

Please sign in to comment.