Minor addition to exception information on failed bulk-load data due to type validation: Mention the failed column and errorneous value
cstim opened this issue · comments
Is your feature request related to a problem? If so, please give a short summary of the problem and how the feature would resolve it
If I do a bulk-load of many columns and many values, and then one of the values fail validation, the corresponding exception does not mention the concerned column name and neither the erroneous value. This makes it unnecessarily difficult to narrow down the wrong value that failed validation.
Describe the preferred solution
In https://github.com/tediousjs/tedious/blob/master/src/bulk-load.ts#L188 please add the c.name
and also the value
to the exception object that is returned. For example by simply adding more properties:
error.column = c.name
error.wrongValue = value
The section of the code would then read:
try { value = c.type.validate(value, c.collation); } catch (error: any) { error.column = c.name error.wrongValue = value return callback(error); }
Of course you are free to add this information to any other of the properties, or even append it to the message. The main point is that these two bits of information should be added to the exception in any form.
Describe alternatives you've considered
hm... the exception here is pretty much exactly the normal error handling. It is simply missing the information about the place where the exception occurred.
@mShan0 @MichaelSun90 Can you take this on? I think it would be best to create a new Error subclass (maybe called ParameterValidationError
), have it inherit from whatever error class we currently use (that might be TypeError
, but I'm not sure), and define the additional properties on that.