Properly catching invalid connection init level errors
See original GitHub issuecreateConnection
connect with database as soon its called. So you can query directly like
let connection = mysql2.createConnection({});
connection.query('SELECT 1+1');
But this pose an issue, say when you pass invalid credentials. It will throw an async error which cannot be caught unless we use process.uncaughtException
or domains
.
Is there any way we can handle this error properly without using hacks. This is also a deviation
from node-mysql
API, which allow creating connections without actually connecting.
May be we should add a version of createConnection
which does not connect with server unless we explicitly call connect
. So if connect
fails we can handle any errors properly.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Error handling - Apollo GraphQL Docs
OPERATION_RESOLUTION_FAILURE. The request was parsed successfully and is valid against the server's schema, but the server couldn't resolve which operation to ...
Read more >Handle errors in ASP.NET Core Blazor apps - Microsoft Learn
Discover how ASP.NET Core Blazor manages unhandled exceptions and how to develop apps that detect and handle errors.
Read more >A connection was successfully established with the server, but ...
I was trying to run asp.net website in local PC, which has connection string of Production DB, following is stack trace for error...
Read more >Get Started with Custom Error Handling in Spring Boot (Java)
Learn how to implement custom error handling logic in Spring Boot. You will see two approaches based on the @ControllerAdvice annotation.
Read more >A Definitive Guide to Handling Errors in JavaScript - Kinsta
You could also run into this error if you forget that the said reference is a constant and use it as a variable....
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
I found
connect
event, Let me try thisPlease check this test case https://github.com/sidorares/node-mysql2/pull/356