davsclaus commented on code in PR #27552:
URL: https://github.com/apache/camel/pull/27552#discussion_r4220146844


##########
components/camel-dataweave/src/test/java/org/apache/camel/component/dataweave/DataWeaveParserTest.java:
##########
@@ -277,10 +277,10 @@ void shouldRepresentMatchExpressionAsUnsupported() {
     }
 
     @Test
-    void shouldNotThrowOnUnbalancedInput() {
-        List<Token> tokens = new DataWeaveLexer("(a + b").tokenize();
-        assertEquals(DataWeaveLexer.TokenType.EOF, tokens.get(tokens.size() - 
1).type());
-        // expect() silently skips a missing RPAREN, so a best-effort AST is 
still produced
-        assertInstanceOf(Parens.class, parseExpr("(a + b"));
+    void shouldThrowOnUnbalancedInput() {
+        // expect() now throws DataWeaveConversionException on a missing RPAREN
+        org.junit.jupiter.api.Assertions.assertThrows(
+                DataWeaveConversionException.class,
+                () -> parseExpr("(a + b"));

Review Comment:
   CLAUDE.md asks for imports instead of fully qualified class names, and the 
rewrite plugin will shorten this, so CI fails on uncommitted changes. With 
`import static org.junit.jupiter.api.Assertions.assertThrows;` added next to 
the other static imports:
   ```suggestion
           assertThrows(
                   DataWeaveConversionException.class,
                   () -> parseExpr("(a + b"));
   ```



##########
components/camel-dataweave/src/main/java/org/apache/camel/component/dataweave/DataWeaveParser.java:
##########
@@ -592,10 +592,11 @@ private DataWeaveAst parsePrimary() {
             return new DataWeaveAst.UnaryOp("-", operand);
         }
 
-        // Fallback: skip token
-        String val = current().value();
-        advance();
-        return new DataWeaveAst.Unsupported(val, "unexpected token");
+        // Unknown token — strict mode: report location and token
+        Token cur = current();
+        throw new DataWeaveConversionException(
+                "DataWeave parse error at " + cur.line() + ":" + cur.col()
+                                               + ": unexpected token " + 
cur.type() + " ('" + cur.value() + "')");

Review Comment:
   This fallback is also how `camel transform dataweave` (`TransformDataWeave`) 
handles valid DataWeave the parser doesn't know yet: it used to become an 
`Unsupported` node, which the CLI prints as `// TODO: manual conversion 
needed`. Throwing here makes that best-effort migration tool fail the whole 
file, and in directory mode it stops the remaining files too.
   
   Could this keep returning `Unsupported` (perhaps with the line:col in the 
reason) and leave `expect()` strict? The language still fails fast, because any 
`Unsupported` node raises `getTodoCount()`, which now throws in 
`DatasonnetLanguage`. Alternatively, the CLI could catch 
`DataWeaveConversionException` per file and report it.



##########
components/camel-datasonnet/src/test/java/org/apache/camel/language/datasonnet/DataWeaveExecutedCorpusTest.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.language.datasonnet;
+
+import com.datasonnet.document.MediaTypes;
+import org.apache.camel.component.dataweave.DataWeaveConversionException;

Review Comment:
   Import order: impsort puts `org.apache.camel.RoutesBuilder` before 
`org.apache.camel.component.dataweave.*`, so CI's uncommitted-changes check 
will flag this. Running `mvn impsort:sort` in the module fixes it.



-- 
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]

Reply via email to