Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7D4517354 for ; Mon, 19 Dec 2011 22:59:02 +0000 (UTC) Received: (qmail 85096 invoked by uid 500); 19 Dec 2011 22:59:02 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 85074 invoked by uid 500); 19 Dec 2011 22:59:02 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Delivered-To: moderator for commits@cassandra.apache.org Received: (qmail 75871 invoked by uid 99); 19 Dec 2011 22:53:08 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of 3OcDvTiAMAPQYWooWjZnW-jkZa.WlWYda-atpnWo.kncYkZaolkp.Yki@codesite.bounces.google.com designates 209.85.216.204 as permitted sender) MIME-Version: 1.0 X-Generated-By: Google Code Message-ID: <20cf300fafbfdc1bc004b479cece@google.com> Date: Mon, 19 Dec 2011 22:52:41 +0000 Subject: [cassandra-node] push by tomaz.muraus - Allow user to pass optional connection info to amendError and if provi... on 2011-12-19 22:51 GMT From: cassandra-node.apache-extras.org@codespot.com To: commits@cassandra.apache.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes X-Virus-Checked: Checked by ClamAV on apache.org Revision: 3d53cb35fd30 Author: Tomaz Muraus 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);