[ 
https://issues.apache.org/jira/browse/CURATOR-448?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16509647#comment-16509647
 ] 

ASF GitHub Bot commented on CURATOR-448:
----------------------------------------

Github user keith-turner commented on a diff in the pull request:

    https://github.com/apache/curator/pull/267#discussion_r194743349
  
    --- Diff: 
curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
 ---
    @@ -402,75 +402,72 @@ public String getNamespace()
             return (str != null) ? str : "";
         }
     
    +    private void checkState()
    +    {
    +        CuratorFrameworkState state = getState();
    +        Preconditions.checkState(state == CuratorFrameworkState.STARTED, 
"instance state must be %s before calling this method, however its %s", 
CuratorFrameworkState.STARTED, state);
    --- End diff --
    
    Could make it less wordy, like : `Expected state %s, however it was %s`


> Include curator framework state in error messages
> -------------------------------------------------
>
>                 Key: CURATOR-448
>                 URL: https://issues.apache.org/jira/browse/CURATOR-448
>             Project: Apache Curator
>          Issue Type: Improvement
>            Reporter: Keith Turner
>            Assignee: Jordan Zimmerman
>            Priority: Major
>
> While looking into [Apache Fluo 
> #1004|https://github.com/apache/fluo/pull/1004] I am seeing error messages 
> like the following.  
>  
> {noformat}
> 2018-01-22 02:57:23,383 [leader.LeaderSelector] ERROR: The leader threw an 
> exception
> java.lang.IllegalStateException: instance must be started before calling this 
> method
> at com.google.common.base.Preconditions.checkState(Preconditions.java:149)
> at 
> org.apache.curator.framework.imps.CuratorFrameworkImpl.getData(CuratorFrameworkImpl.java:363)
> at 
> org.apache.fluo.core.oracle.OracleServer.takeLeadership(OracleServer.java:426)
> TRUNCATED{noformat}
>  
> When I see this error message I know the  
> [CuratorFrameworkState|https://curator.apache.org/apidocs/org/apache/curator/framework/imps/CuratorFrameworkState.html]
>  is not STARTED.  However I don't know if its LATENT or STOPPED.  From a 
> debugging standpoint this information would be very useful.  An example of 
> the code that generates this error messages is at [CuratorFrameworkImpl.java 
> line 
> 408|https://github.com/apache/curator/blob/3f7b610ad5c5a0c6a7b0331f02294bd433a54554/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java#L408].
>   This code could be changed to call an internal method like the following :
>  
> {code:java}
> private void checkState() {
>   CuratorFrameworkState state = getState(); //store state in local var to 
> avoid race conditions since it may be read twice
>   Preconditions.checkState(state == CuratorFrameworkState.STARTED, "instance 
> state must be %s before calling this method, however its %s", 
> CuratorFrameworkState.STARTED, state);
> }
> {code}
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to