more user-friendly error messages for unknown host and connection failures
patch by Noa Resare; reviewed by jbellis for CASSANDRA-4224


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/641346b0
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/641346b0
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/641346b0

Branch: refs/heads/trunk
Commit: 641346b0dc85a723f1bd755007c334b310c71e67
Parents: 8b81c8f
Author: Jonathan Ellis <jbel...@apache.org>
Authored: Tue May 8 16:53:49 2012 -0500
Committer: Jonathan Ellis <jbel...@apache.org>
Committed: Tue May 8 16:54:01 2012 -0500

----------------------------------------------------------------------
 src/java/org/apache/cassandra/tools/NodeCmd.java |   23 ++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/641346b0/src/java/org/apache/cassandra/tools/NodeCmd.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/NodeCmd.java 
b/src/java/org/apache/cassandra/tools/NodeCmd.java
index 07f560d..e33f698 100644
--- a/src/java/org/apache/cassandra/tools/NodeCmd.java
+++ b/src/java/org/apache/cassandra/tools/NodeCmd.java
@@ -24,6 +24,7 @@ package org.apache.cassandra.tools;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.lang.management.MemoryUsage;
+import java.net.ConnectException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.text.DecimalFormat;
@@ -660,7 +661,21 @@ public class NodeCmd
         }
         catch (IOException ioe)
         {
-            err(ioe, "Error connection to remote JMX agent!");
+            Throwable inner = findInnermostThrowable(ioe);
+            if (inner instanceof ConnectException)
+            {
+                System.err.printf("Failed to connect to '%s:%d': %s\n", host, 
port, inner.getMessage());
+                System.exit(1);
+            }
+            else if (inner instanceof UnknownHostException)
+            {
+                System.err.printf("Cannot resolve '%s': unknown host\n", host);
+                System.exit(1);
+            }
+            else
+            {
+                err(ioe, "Error connecting to remote JMX agent!");
+            }
         }
         try
         {
@@ -856,6 +871,12 @@ public class NodeCmd
         System.exit(0);
     }
 
+    private static Throwable findInnermostThrowable(Throwable ex)
+    {
+        Throwable inner = ex.getCause();
+        return inner == null ? ex : findInnermostThrowable(inner);
+    }
+
     private void printDescribeRing(String keyspaceName, PrintStream out)
     {
         out.println("Schema Version:" + probe.getSchemaVersion());

Reply via email to