async pool.execute still throws error although inside try catch
See original GitHub issuewhen passing undifiend to pool.execute throws error and node crashes connection.execute works fine and execption is handled
import mysql = require('mysql2');
async function x1() {
let pool = await mysql.createPool({
host: 'localhost',user: 'nodejs',
password: 'nodejs', database: 'convfourierDB',
port: 3306, debug: false })
.promise()
try {
await pool.execute('select * from inventory where id=?', [undefined])
console.log('x')
}
catch (error){
console.log(error)
} }
x1()
when getting connection then execute works fine and execption is handled
async function x1() {
let pool = await mysql.createPool({
host: 'localhost', user: 'nodejs',
password: 'nodejs', database: 'convfourierDB',
port: 3306, debug: false })
.promise()
let conn = await pool.getConnection()
try {
await conn.execute('select * from inventory where id=?', [undefined])
console.log('x') }
catch (error) {
console.log(error)
} }
x1()
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why does exception still get thrown after catch in async ...
It doesn't go to the catch because the bad() is terminated by the error. (Even if it weren't, it wouldn't return a promise.)...
Read more >Async/Await - Best Practices in Asynchronous Programming
When you await a Task, the first exception is re-thrown, so you can catch the specific exception type (such as InvalidOperationException). However, when...
Read more >Futures and error handling - Dart programming language
Async try -catch-finally using whenComplete() ... If then().catchError() mirrors a try-catch, whenComplete() is the equivalent of 'finally'. The callback ...
Read more >Don't Block the Event Loop (or the Worker Pool) - Node.js
If a thread is taking a long time to execute a callback (Event Loop) or a task (Worker), we call it "blocked". While...
Read more >C# Async Antipatterns - Mark Heath
But in most cases, I recommend against using async void . If you can make your method return a Task , you should...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
the problem is here - https://github.com/sidorares/node-mysql2/blob/dadef383098b0823a90e07fbec18639bd612adfb/lib/pool.js#L177
I think we need to change
throw e;
intoreturn cb(e);
but want to be careful and discuss what that could mean for backwards compatibility. Might require a major releaseHello guys, I just encounter this behavior. Throwing errors from callback functions are simply not catchable and I support the fix using
return cb(e)
.In my opinion you don’t need major release for such a fix, since this error could only be caught using
process.on('uncaughtException'
handler or it is going to crash your app otherwise.I don’t see how it could break any backward code.
It’s good that there is a workaround.
Looking forward for the fix. Cheers!