Skip to content

Commit

Permalink
more user-friendly error messages for unknown host and connection fai…
Browse files Browse the repository at this point in the history
…lures

patch by Noa Resare; reviewed by jbellis for CASSANDRA-4224
  • Loading branch information
jbellis committed May 8, 2012
1 parent 8b81c8f commit 641346b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/java/org/apache/cassandra/tools/NodeCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -660,7 +661,21 @@ public static void main(String[] args) throws IOException, InterruptedException,
}
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
{
Expand Down Expand Up @@ -856,6 +871,12 @@ public static void main(String[] args) throws IOException, InterruptedException,
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());
Expand Down

0 comments on commit 641346b

Please sign in to comment.