gmunozfe commented on code in PR #3756:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3756#discussion_r1824336012


##########
kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/ActionNodeUtils.java:
##########
@@ -34,16 +34,21 @@ public class ActionNodeUtils {
         return 
embeddedSubProcess.actionNode(context.newId()).name(functionDef.getName());
     }
 
-    public static void checkArgs(FunctionRef functionRef, String... 
requiredArgs) {
+    public static boolean checkArgs(ParserContext context, FunctionRef 
functionRef, String... requiredArgs) {
         JsonNode args = functionRef.getArguments();
+        boolean isOk = true;

Review Comment:
   Instead of setting `isOk` to false and continuing the checks, you could 
return `false` immediately after adding a validation error. This will remove 
the need for the `isOk` flag entirely, making the code more readable. Wdyt?
   
   ```suggestion
   ```



##########
kogito-serverless-workflow/kogito-serverless-workflow-executor-core/src/test/java/org/kie/kogito/serverless/workflow/executor/StaticWorkflowApplicationTest.java:
##########
@@ -107,6 +109,17 @@ void interpolationFile(String fileName, WorkflowFormat 
format) throws IOExceptio
         }
     }
 
+    @Test
+    void testValidationError() throws IOException {
+        try (Reader reader = new 
InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("wrong.sw.json"));
+                StaticWorkflowApplication application = 
StaticWorkflowApplication.create()) {
+            Workflow workflow = getWorkflow(reader, WorkflowFormat.JSON);
+            ValidationException validationException = catchThrowableOfType(() 
-> application.process(workflow), ValidationException.class);
+            
assertThat(validationException.getErrors()).hasSizeGreaterThanOrEqualTo(4);

Review Comment:
   Why also greater? Shouldn't it be equal to 4 always?



##########
kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/parser/handlers/ActionNodeUtils.java:
##########
@@ -34,16 +34,21 @@ public class ActionNodeUtils {
         return 
embeddedSubProcess.actionNode(context.newId()).name(functionDef.getName());
     }
 
-    public static void checkArgs(FunctionRef functionRef, String... 
requiredArgs) {
+    public static boolean checkArgs(ParserContext context, FunctionRef 
functionRef, String... requiredArgs) {
         JsonNode args = functionRef.getArguments();
+        boolean isOk = true;
         if (args == null) {
-            throw new IllegalArgumentException("Arguments cannot be null for 
function " + functionRef.getRefName());
-        }
-        for (String arg : requiredArgs) {
-            if (!args.has(arg)) {
-                throw new IllegalArgumentException("Missing mandatory " + arg 
+ " argument for function " + functionRef.getRefName());
+            context.addValidationError("Arguments cannot be null for function 
" + functionRef.getRefName());
+            isOk = false;
+        } else {
+            for (String arg : requiredArgs) {
+                if (!args.has(arg)) {
+                    context.addValidationError("Missing mandatory " + arg + " 
argument for function " + functionRef.getRefName());
+                    isOk = false;
+                }
             }
         }
+        return isOk;

Review Comment:
   This part without the `isOk` flag would be:
   
   ```suggestion
               context.addValidationError("Arguments cannot be null for 
function " + functionRef.getRefName());
               return false;
           } 
           for (String arg : requiredArgs) {
               if (!args.has(arg)) {
                   context.addValidationError("Missing mandatory " + arg + " 
argument for function " + functionRef.getRefName());
                   return false;
               }
           }
           return true;
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to