accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From md...@apache.org
Subject [02/10] git commit: ACCUMULO-2404 Better error logging in start.Main
Date Tue, 25 Feb 2014 19:53:08 GMT
ACCUMULO-2404 Better error logging in start.Main

Propogate original exceptions instead of the wrapping
InvocationTargetException when possible, when starting processes
through o.a.a.start.Main


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/1543d65f
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/1543d65f
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/1543d65f

Branch: refs/heads/1.5.1-SNAPSHOT
Commit: 1543d65fb2ff54ede7785f591f30f3764622b4df
Parents: 2829426
Author: Mike Drob <mdrob@cloudera.com>
Authored: Tue Feb 25 11:41:51 2014 -0500
Committer: Mike Drob <mdrob@cloudera.com>
Committed: Tue Feb 25 11:41:51 2014 -0500

----------------------------------------------------------------------
 .../java/org/apache/accumulo/start/Main.java    | 34 +++++++++++++++-----
 1 file changed, 26 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/1543d65f/src/start/src/main/java/org/apache/accumulo/start/Main.java
----------------------------------------------------------------------
diff --git a/src/start/src/main/java/org/apache/accumulo/start/Main.java b/src/start/src/main/java/org/apache/accumulo/start/Main.java
index 53c31a5..f955dd8 100644
--- a/src/start/src/main/java/org/apache/accumulo/start/Main.java
+++ b/src/start/src/main/java/org/apache/accumulo/start/Main.java
@@ -16,14 +16,15 @@
  */
 package org.apache.accumulo.start;
 
-import org.apache.accumulo.start.classloader.AccumuloClassLoader;
-
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
+import org.apache.accumulo.start.classloader.AccumuloClassLoader;
+
 public class Main {
-  
-  public static void main(String[] args) throws Exception {
+
+  public static void main(String[] args) {
     Runnable r = null;
     
     try {
@@ -89,10 +90,15 @@ public class Main {
         public void run() {
           try {
             finalMain.invoke(null, thisIsJustOneArgument);
+          } catch (InvocationTargetException e) {
+            if (e.getCause() != null) {
+              die(e.getCause());
+            } else {
+              // Should never happen, but check anyway.
+              die(e);
+            }
           } catch (Exception e) {
-            System.err.println("Thread \"" + Thread.currentThread().getName() + "\" died
" + e.getMessage());
-            e.printStackTrace(System.err);
-            System.exit(1);
+            die(e);
           }
         }
       };
@@ -105,7 +111,19 @@ public class Main {
       t.printStackTrace(System.err);
     }
   }
-  
+
+  /**
+   * Print a stack trace to stderr and exit with a non-zero status.
+   *
+   * @param t
+   *          The {@link Throwable} containing a stack trace to print.
+   */
+  private static void die(Throwable t) {
+    System.err.println("Thread \"" + Thread.currentThread().getName() + "\" died " + t.getMessage());
+    t.printStackTrace(System.err);
+    System.exit(1);
+  }
+
   private static void printUsage() {
     System.out.println("accumulo init | master | tserver | logger | monitor | shell | admin
| gc | classpath | <accumulo class> args");
   }


Mime
View raw message