Skip to content

Commit 6e5d848

Browse files
committed
Evaluation errors are returned as result
1 parent 9ceaeea commit 6e5d848

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/main/java/org/seedstack/coffig/evaluator/FunctionEvaluator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public TreeNode evaluate(TreeNode rootNode, TreeNode valueNode) {
8888
try {
8989
return processValue(rootNode, valueNode.value());
9090
} catch (Exception e) {
91-
LOGGER.error("Error when evaluating configuration function: {}", valueNode.value(), e);
92-
return new ValueNode();
91+
LOGGER.debug("Error when evaluating configuration function: {}", valueNode.value(), e);
92+
return new ValueNode(TreeNode.formatNodeError(e));
9393
}
9494
} else {
9595
return valueNode;

src/main/java/org/seedstack/coffig/evaluator/MacroEvaluator.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
package org.seedstack.coffig.evaluator;
99

1010
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11-
import java.util.Optional;
12-
import java.util.regex.Matcher;
13-
import java.util.regex.Pattern;
1411
import org.seedstack.coffig.TreeNode;
1512
import org.seedstack.coffig.node.ValueNode;
1613
import org.seedstack.coffig.spi.ConfigurationEvaluator;
1714
import org.slf4j.Logger;
1815
import org.slf4j.LoggerFactory;
1916

17+
import java.util.Optional;
18+
import java.util.regex.Matcher;
19+
import java.util.regex.Pattern;
20+
2021
public class MacroEvaluator implements ConfigurationEvaluator {
2122
public static final String VALUE_QUOTE = "'";
2223
public static final String VALUE_SEPARATOR = ":";
@@ -34,8 +35,8 @@ public TreeNode evaluate(TreeNode rootNode, TreeNode valueNode) {
3435
try {
3536
return new ValueNode(processValue(rootNode, valueNode.value()));
3637
} catch (Exception e) {
37-
LOGGER.error("Error when evaluating configuration macro: {}", valueNode.value(), e);
38-
return new ValueNode();
38+
LOGGER.debug("Error when evaluating configuration macro: {}", valueNode.value(), e);
39+
return new ValueNode(TreeNode.formatNodeError(e));
3940
}
4041
} else {
4142
return valueNode;
@@ -54,24 +55,24 @@ private String processValue(TreeNode rootNode, String value) {
5455
// Process all macros
5556
while ((matchingResult = findMatchingCurlyBraces(value, currentPos)) != null) {
5657
// Add the beginning of the string (before the macro)
57-
result.append(value.substring(currentPos, matchingResult.startPos));
58+
result.append(value, currentPos, matchingResult.startPos);
5859

5960
if (matchingResult.escaped) {
6061
// Add the macro as-is (without resolving it)
61-
result.append(value.substring(matchingResult.startPos + 1, matchingResult.endPos + 1));
62+
result.append(value, matchingResult.startPos + 1, matchingResult.endPos + 1);
6263
} else {
6364
// Process the macro
6465
boolean insideQuotes = false;
6566
for (String part : value.substring(matchingResult.startPos + 2, matchingResult.endPos)
6667
.split(VALUE_SEPARATOR)) {
6768
if (part.startsWith(VALUE_QUOTE) && part.endsWith(VALUE_QUOTE)) {
68-
result.append(part.substring(1, part.length() - 1));
69+
result.append(part, 1, part.length() - 1);
6970
break;
7071
} else if (!insideQuotes && part.startsWith(VALUE_QUOTE)) {
7172
result.append(part.substring(1));
7273
insideQuotes = true;
7374
} else if (insideQuotes && part.endsWith(VALUE_QUOTE)) {
74-
result.append(VALUE_SEPARATOR).append(part.substring(0, part.length() - 1));
75+
result.append(VALUE_SEPARATOR).append(part, 0, part.length() - 1);
7576
insideQuotes = false;
7677
} else if (insideQuotes) {
7778
result.append(VALUE_SEPARATOR).append(part);

src/main/java/org/seedstack/coffig/mapper/PropertiesMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Object map(TreeNode treeNode, Type type) {
3434
if (treeNode.type() == TreeNode.Type.MAP_NODE) {
3535
treeNode.namedNodes()
3636
.forEach(namedNode -> properties.setProperty(namedNode.name(),
37-
Objects.toString((String) coffig.getMapper().map(namedNode.node(), String.class), "")));
37+
Objects.toString(coffig.getMapper().map(namedNode.node(), String.class), "")));
3838
} else {
3939
treeNode.nodes().forEach(item -> properties.setProperty(item.value(), ""));
4040
}

0 commit comments

Comments
 (0)