diff --git a/src/bulk-load.ts b/src/bulk-load.ts index 0625d1924..98676e034 100644 --- a/src/bulk-load.ts +++ b/src/bulk-load.ts @@ -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); } } diff --git a/test/integration/bulk-load-test.js b/test/integration/bulk-load-test.js index 794dc9274..4a7b03bb8 100644 --- a/test/integration/bulk-load-test.js +++ b/test/integration/bulk-load-test.js @@ -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); + + }); });