Comments (2)
I don't know if this really makes it clearer, but to simulate the uncaughtException
, this could be used as the query
function (throws an arbitrary error - if we keep the throw, it will lead to an uncaughtException, regardless of whether the connection has an error handler registered):
...
query(sql, values, cb) {
const cmdQuery = Connection.createQuery(
sql,
values,
cb,
this.config.connectionConfig
);
if (typeof cmdQuery.namedPlaceholders === 'undefined') {
cmdQuery.namedPlaceholders = this.config.connectionConfig.namedPlaceholders;
}
this.getConnection((err, conn) => {
if (err) {
if (typeof cmdQuery.onResult === 'function') {
cmdQuery.onResult(err);
} else {
cmdQuery.emit('error', err);
}
return;
}
try {
// XXXXXX THROW ERROR for demo
throw new Error("Simulated error.");
conn.query(cmdQuery).once('end', () => {
conn.release();
});
} catch (e) {
conn.release();
// if we keep throw e; here, this will raise an uncaughtException:
// throw e;
// XXXXXX SEND ERROR TO CALLBACK INSTEAD OF throw
const actualCb = cb || values; // values is optional
actualCb(e);
// XXXXXX
}
});
return cmdQuery;
}
...
from node-mysql2.
fyi, I'm not so sure whether the calling the callback with the error really is what is desired in terms of "throwing if no one listens any more" etc. Currently I use this workaround (I'm using the promise wrapper):
async queryPool(query: string, values?: any) {
const conn = await pool.getConnection();
try {
const result = await conn.query(query, values);
return result;
} finally {
conn.release();
}
}
I can live with this workaround for now.
from node-mysql2.
Related Issues (20)
- Bulk insert thousands of records results in ER_PS_MANY_PARAM. Should I split my records? HOT 1
- Timeout Issue despite my Connection Settings Being Correct HOT 1
- Can't get the database name after use db command HOT 3
- Alternative for "ResultSetHeader.changedRows" HOT 2
- prepare is not a function
- npm error when using typecast
- namedPlaceholders cannot be disabled at query level
- Remove error being logged for invalid options AND please do not make it ever throw an error for this! HOT 1
- Update examples HOT 1
- Pool not releasing connections if maxIdle is not set HOT 14
- Can't add new command when connection is in closed state
- Weird bug connection pool close just because of select id HOT 4
- insert can use Buffer, but not work with Uint8Array HOT 1
- How to resolve "mysql Proxy Warning - Syntax Forbidden prepare"? HOT 1
- ⨯ node_modules\mysql2\lib\connection_config.js (261:0) @ <unknown> ⨯ URL is not a constructor HOT 2
- Got an error reading communication packets HOT 9
- Updated Amazon RDS SSL CA cert chain is a single string
- Add `connection.end()` call to quickstart documentation HOT 3
- `bigNumberStrings: true` is not respected for LIMIT and OFFSET
- Is there any way to get this library to set the SNI field when establishing a TLS connection? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-mysql2.