sagiegurari / simple-oracledb

Extend capabilities of oracledb with simplified API for quicker development.
Apache License 2.0
36 stars 4 forks source link

When executing batchInsert, DB errors are not available in the callback err param #20

Closed karthikrock closed 7 years ago

karthikrock commented 7 years ago
connection.batchInsert('<INSERT STATEMENT>', [{ //first row values
                id: 110,
                name: 'A'
            },
            { //second row values
                id: 111,
                name: 'B'
            }
        ], {
            autoCommit: false
        }
    },
    function onResults(err, output) {
        if (err) {
            console.log(JSON.stringify(err)); //prints empty object when there is a DB error- {}
        }
    });

It handles the error however there is nothing in the err object to debug/understand what kind of DB error occurred. Version: "simple-oracledb": "~1.1.39".

Is it fixed in any of the newer releases ? Or was it ever reported as an issue ?

sagiegurari commented 7 years ago

From my tests it should work fine. The issue I'm seeing is that you are trying to stringify an error object but that is not the right way to work with errors. for example this would also result in an empty object

JSON.stringify(new Error('test')); // -> {}

So don't use errors like that, use the error.message/error.stack/... See more in mdn: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Error

sagiegurari commented 7 years ago

closing this one. if you have any issues please open a new issue.

karthikrock commented 7 years ago

My bad! yes stringifying Error object makes it {}. I was able to extract the error using the properties. :)