Revision: 3d53cb35fd30
Author: Tomaz Muraus <to...@tomaz.me>
Date: Mon Dec 19 14:50:34 2011
Log: Allow user to pass optional connection info to amendError and if
provided, attach it to the error object.
http://code.google.com/a/apache-extras.org/p/cassandra-node/source/detail?r=3d53cb35fd30
Modified:
/lib/driver.js
=======================================
--- /lib/driver.js Fri Dec 16 08:46:02 2011
+++ /lib/driver.js Mon Dec 19 14:50:34 2011
@@ -126,8 +126,14 @@
UUID = module.exports.UUID = require('uuid-js');
-/** make sure that err.message is set to something that makes sense. */
-function amendError(err) {
+/**
+ * Make sure that err.message is set to something that makes sense.
+ *
+ * @param {Object} err Error object.
+ * @param {Object} connectionInfo Optional connection info object which is
+ * attached to the error.
+ */
+function amendError(err, connectionInfo) {
if (!err.message || err.message.length === 0) {
if (err.name === "NotFoundException") {
err.message = "ColumnFamily or Keyspace does not exist";
@@ -135,6 +141,8 @@
err.message = err.why;
}
}
+
+ err.connectionInfo = connectionInfo;
return err;
}
@@ -309,6 +317,8 @@
],
function(err, res, conn) {
+ var connectionInfo;
+
if (conn) {
self.pool.release(conn);
}
@@ -322,7 +332,8 @@
errback();
}
else {
- err = amendError(err);
+ connectionInfo = (conn) ? conn.connectionInfo : null;
+ err = amendError(err, connectionInfo);
callback(err, res);
}
}
@@ -379,7 +390,7 @@
this.con.on('error', function(err) {
clearTimeout(timeoutId);
- amendError(err);
+ amendError(err, self.connectionInfo);
callback(err);
});
@@ -411,7 +422,7 @@
self.client.login(creds, function(err) {
if (timeoutId) {
timeoutId = clearTimeout(timeoutId);
- if (err) { amendError(err); }
+ if (err) { amendError(err, self.connectionInfo); }
cb(err);
}
});
@@ -432,7 +443,7 @@
if (timeoutId) {
timeoutId = clearTimeout(timeoutId);
if (err) {
- amendError(err);
+ amendError(err, self.connectionInfo);
cb(err);
} else {
for (var i = 0; i < def.cf_defs.length; i++) {
@@ -465,7 +476,7 @@
self.client.set_keyspace(self.connectionInfo.keyspace, function(err)
{
if (timeoutId) {
timeoutId = clearTimeout(timeoutId);
- if (err) { amendError(err); }
+ if (err) { amendError(err, self.connectionInfo); }
cb(err);
}
});
@@ -540,7 +551,7 @@
}
if (err) {
- amendError(err);
+ amendError(err, self.connectionInfo);
callback(err, null);
} else if (!res) {
callback(new Error('No results'), null);