This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 832e852 CAMEL-17806: camel-yaml-dsl - Better parser error with source
loc:line of the problem
832e852 is described below
commit 832e85296aa22d3db2ba1ac365a9d4531caa7a6d
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Mar 31 17:39:27 2022 +0200
CAMEL-17806: camel-yaml-dsl - Better parser error with source loc:line of
the problem
---
.../exception/InvalidExpressionException.java | 30 ++++++++++++++++++++++
.../deserializers/ExpressionDeserializers.java | 6 ++++-
.../dsl/yaml/GenerateYamlDeserializersMojo.java | 6 ++++-
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/exception/InvalidExpressionException.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/exception/InvalidExpressionException.java
new file mode 100644
index 0000000..9274d99
--- /dev/null
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/exception/InvalidExpressionException.java
@@ -0,0 +1,30 @@
+/*
+ * 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.dsl.yaml.common.exception;
+
+import java.util.Optional;
+
+import org.snakeyaml.engine.v2.exceptions.MarkedYamlEngineException;
+import org.snakeyaml.engine.v2.nodes.Node;
+
+public class InvalidExpressionException extends MarkedYamlEngineException {
+
+ public InvalidExpressionException(Node node, String message) {
+ super(null, Optional.empty(), message, node != null ?
node.getStartMark() : Optional.empty());
+ }
+
+}
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ExpressionDeserializers.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ExpressionDeserializers.java
index 1f820d2..6042491 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ExpressionDeserializers.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ExpressionDeserializers.java
@@ -27,7 +27,11 @@ public final class ExpressionDeserializers extends
YamlDeserializerSupport {
YamlDeserializationContext dc = getDeserializationContext(node);
String key = asText(nt.getKeyNode());
Node val = setDeserializationContext(nt.getValueNode(), dc);
- return constructExpressionType(key, val);
+ ExpressionDefinition answer = constructExpressionType(key, val);
+ if (answer == null) {
+ throw new
org.apache.camel.dsl.yaml.common.exception.InvalidExpressionException(node,
"Unknown expression with id: " + key);
+ }
+ return answer;
}
public static ExpressionDefinition constructExpressionType(String id, Node
node) {
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlDeserializersMojo.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlDeserializersMojo.java
index f17f18b..e52d7ab 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlDeserializersMojo.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-maven-plugin/src/main/java/org/apache/camel/maven/dsl/yaml/GenerateYamlDeserializersMojo.java
@@ -142,7 +142,11 @@ public class GenerateYamlDeserializersMojo extends
GenerateYamlSupportMojo {
.addStatement("$T dc = getDeserializationContext(node)",
CN_DESERIALIZATION_CONTEXT)
.addStatement("String key = asText(nt.getKeyNode())")
.addStatement("$T val =
setDeserializationContext(nt.getValueNode(), dc)", CN_NODE)
- .addStatement("return constructExpressionType(key, val)")
+ .addStatement("ExpressionDefinition answer =
constructExpressionType(key, val)")
+ .beginControlFlow("if (answer == null)")
+ .addStatement("throw new
org.apache.camel.dsl.yaml.common.exception.InvalidExpressionException(node,
\"Unknown expression with id: \" + key)")
+ .endControlFlow()
+ .addStatement("return answer")
.build())
.build());