[ 
https://issues.apache.org/jira/browse/BEAM-5141?focusedWorklogId=134730&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-134730
 ]

ASF GitHub Bot logged work on BEAM-5141:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/Aug/18 21:07
            Start Date: 14/Aug/18 21:07
    Worklog Time Spent: 10m 
      Work Description: akedin commented on a change in pull request #6216: 
[BEAM-5141] Improve error message when SET unregistered options
URL: https://github.com/apache/beam/pull/6216#discussion_r210103331
 
 

 ##########
 File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java
 ##########
 @@ -1512,20 +1512,33 @@ public int compare(Method o1, Method o2) {
                   Sets.filter(
                       propertyNamesToGetters.keySet(),
                       input -> 
StringUtils.getLevenshteinDistance(entry.getKey(), input) <= 2));
+
+          PipelineOptionUnexpectedPropertyException exception;
           switch (closestMatches.size()) {
             case 0:
-              throw new IllegalArgumentException(
-                  String.format("Class %s missing a property named '%s'.", 
klass, entry.getKey()));
+              exception =
+                  new PipelineOptionUnexpectedPropertyException(
+                      String.format(
+                          "Class %s missing a property named '%s'.", klass, 
entry.getKey()));
 
 Review comment:
   I think it can be simplified by moving all of this logic into the exception, 
so that here you will only need to call `throw 
PipelineOptionUnexpectedPropertyException.create(entry.getKey(), klass, 
closestMatches)` without switching.
   
   And within the `PipelineOptionUnexpectedPropertyException` I would have 
something like this:
   ```java
   
   PipelineOptionUnexpectedPropertyException extends IllegalArgumentException {
     ...
     private PipelineOptionUnexpectedPropertyException(option, klass, 
closestMatches) {
         super(createMessage(option, klass, closestMatches));
         this.optionsClass = klass;
         ...
     }
     ...
     public static PipelineOptionUnexpectedPropertyException create(...) { 
return new ...; }
     ...  
     public Class getPipelineOptionsClass() { return optionsClass; }
     ...
     private static String createMessage(option, klass, closestMatches) {
       String message = "Class " + klass " missing a property named '" + 
option"'.";
       switch (closestMatches.size()) {
          case 0: return message;
          case 1: return message + " Did you mean " + ....;
          default: return message + " Did you mean " + ...;
       }
     }
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 134730)
    Time Spent: 3h 10m  (was: 3h)

> Improve error message when SET unregistered options 
> ----------------------------------------------------
>
>                 Key: BEAM-5141
>                 URL: https://issues.apache.org/jira/browse/BEAM-5141
>             Project: Beam
>          Issue Type: Improvement
>          Components: dsl-sql
>            Reporter: Rui Wang
>            Assignee: Rui Wang
>            Priority: Major
>          Time Spent: 3h 10m
>  Remaining Estimate: 0h
>




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

Reply via email to