Open abney317 opened 4 years ago
No, it's just not implemented ( here is how mysqljs is doing it ). The reason was partially performance ( having new Error()
anywhere in the code used to prevent v8 from some optimisations even if it's behind the flag ), it's much better now so I might consider adding
You can do it yourself in your code by adding 3rd party long stack trace library such as https://github.com/mattinsler/longjohn
With async/await it's handled automatically by v8, so promise wrapper has much better stacks
it's frustrating having to hunt around because the stack trace is useless, could you please consider making this a priority if it's easy to do
And can just hide behind a flag if you're so worried about performance?
Came here while troubleshooting similar issues in a codebase using knex+mysql2. I don't think there is a way to make knex use the promise wrapper.
Just came here to bump this because having useless stack traces is exceedingly frustrating when trying to debug. Is there any ETA on when this might be looked at/considered for implementation? If not I may have to revert to using mysqljs because it's just not feasible to be unable to track down issues when they are impacting production environment
I had this issue because I was wrapping con.query in my own promise wrapper.
Once I updated my code to use 'mysql2/promise' the stack traces were helpful again.
Error: Unknown column 'invalid' in 'field list'
at PromisePoolConnection.query (/home/k1z4/Utils/node_modules/mysql2/promise.js:94:22)
at FriendRepository.query (file:///home/k1z4/Utils/src/mysqlBase.js:6:21)
at FriendRepository.insert (file:///home/k1z4/Utils/src/mysqlBase.js:72:27)
at file:///home/k1z4/Utils/test/testApp.js:43:28
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async FriendRepository.inTransaction (file:///home/k1z4/Utils/src/mysqlBase.js:105:32)
at async file:///home/k1z4/Utils/test/testApp.js:76:1 {
code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sql: "INSERT INTO friend SET `name` = 'test4', `invalid` = 'invalid'",
sqlState: '42S22',
sqlMessage: "Unknown column 'invalid' in 'field list'"
}
My new query func with useful stack traces:
static query(sqlString, params, pool = getPool()) {
return pool.query(sqlString, params).then(([rows, fields]) => rows)
}
My old query func with bad stack traces:
static query(sqlString, params, con = getPool()) {
if (typeof (sqlString) !== 'string') throw new Error("sqlString must be a string");
if (!typeof params == 'object') throw new Error("params must be an object");
return new Promise((resolve, reject) => {
con.query(sqlString, params, (error, results, fields) => {
if (error) {
return reject(error);
}
resolve(results, fields);
});
});
}
Yes, I have just found this bug, that after migrating from npm/mysql to npm/mysql2 traces are lost. Option trace : true/false
described in mysql lib https://github.com/mysqljs/mysql#connection-options is not working in this mysql2 lib. Unfortunately we can not migrate to mysql2 due to this bug.
UPDATE: It should be added here: https://github.com/sidorares/node-mysql2/tree/master/documentation/en#known-incompatibilities-with-node-mysql that trace
option not working/not supported/not implemented.
I am unable to see the long version of the stack traces from errors.
Becomes a bit difficult to debug things without any of my own code referenced in the stack trace.
Node MySQL has the long stack traces. Is there a way to enable this, am I missing something, or has it just not been implemented here for MySQL2?