CURATOR-71 do not log-and-throw
authorMike Drob <mdrob@cloudera.com>
Fri, 1 Aug 2014 17:08:47 +0000 (12:08 -0500)
committerMike Drob <mdrob@cloudera.com>
Fri, 1 Aug 2014 17:08:47 +0000 (12:08 -0500)
If we throw an exception, then there is no point in logging it since
something further up the call stack already has to deal with it. At
best, the exception gets logged twice, at worst we log potentially
confusing exceptions that end up not mattering.

curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java
curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelector.java
curator-recipes/src/main/java/org/apache/curator/framework/recipes/locks/StandardLockInternalsDriver.java
curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java

index f14214f..09b28b2 100644 (file)
@@ -182,9 +182,8 @@ public class CuratorZookeeperClient implements Closeable
 
         if ( !started.compareAndSet(false, true) )
         {
-            IllegalStateException error = new IllegalStateException();
-            log.error("Already started", error);
-            throw error;
+            IllegalStateException ise = new IllegalStateException("Already started");
+            throw ise;
         }
 
         state.start();
index 01cacee..e86b1e5 100644 (file)
@@ -233,9 +233,8 @@ public class CuratorFrameworkImpl implements CuratorFramework
         log.info("Starting");
         if ( !state.compareAndSet(CuratorFrameworkState.LATENT, CuratorFrameworkState.STARTED) )
         {
-            IllegalStateException error = new IllegalStateException();
-            log.error("Cannot be started more than once", error);
-            throw error;
+            IllegalStateException ise = new IllegalStateException("Cannot be started more than once");
+            throw ise;
         }
 
         try
index e7b61f9..3be941a 100644 (file)
@@ -418,7 +418,6 @@ public class LeaderSelector implements Closeable
         }
         catch ( Exception e )
         {
-            log.error("mutex.acquire() threw an exception", e);
             throw e;
         }
         finally
index d225bbb..25f07b8 100644 (file)
@@ -61,7 +61,6 @@ public class StandardLockInternalsDriver implements LockInternalsDriver
     {
         if ( ourIndex < 0 )
         {
-            log.error("Sequential path not found: " + sequenceNodeName);
             throw new KeeperException.NoNodeException("Sequential path not found: " + sequenceNodeName);
         }
     }
index 08cbe17..2b07586 100644 (file)
@@ -320,7 +320,6 @@ public class PersistentEphemeralNode implements Closeable
             }
             catch ( Exception e )
             {
-                log.error("Deleting node: " + localNodePath, e);
                 throw e;
             }
         }
@@ -341,8 +340,7 @@ public class PersistentEphemeralNode implements Closeable
         }
         catch ( Exception e )
         {
-            log.error("Creating node. BasePath: " + basePath, e);
-            throw new RuntimeException(e);  // should never happen unless there's a programming error - so throw RuntimeException
+            throw new RuntimeException("Creating node. BasePath: " + basePath, e);  // should never happen unless there's a programming error - so throw RuntimeException
         }
     }
 
@@ -362,7 +360,6 @@ public class PersistentEphemeralNode implements Closeable
             }
             catch ( Exception e )
             {
-                log.error("Watching node: " + localNodePath, e);
                 throw e;
             }
         }