gnodet-bot commented on code in PR #26617:
URL: https://github.com/apache/camel/pull/26617#discussion_r4056280501
##########
dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/main/java/org/apache/camel/dsl/yaml/validator/YamlValidator.java:
##########
@@ -214,6 +220,216 @@ static Error parseError(Exception e, String content) {
.build();
}
+ private static final Pattern SNAKE_MARK = Pattern.compile("in 'reader',
line (\\d+), column (\\d+):");
+ private static final Pattern ESCAPE_CHAR = Pattern.compile("found unknown
escape character (.)\\(");
+ private static final Pattern KEY_LINE =
Pattern.compile("^\\s*[^-\\s#][^:]*:(\\s|$)");
+
+ /** A position the parser reported: the line and the column it points at,
both 1-based. */
+ private record Mark(int line, int column) {
+ }
+
+ /**
+ * CAMEL-24837: the snakeyaml messages that only say where the parser gave
up, said in YAML words. Returns null for
+ * the messages this does not know, so the raw one is still reported.
+ */
+ static Error indentationError(String msg, String[] lines) {
+ List<Mark> marks = marks(msg, lines);
+ if (marks.isEmpty()) {
+ return null;
+ }
+ Mark problem = marks.get(marks.size() - 1);
+ // the stray item is named '-', or '<block sequence start>' when the
list it broke uses bare dashes
+ if (msg.contains("expected <block end>, but found '-'")
+ || msg.contains("expected <block end>, but found '<block
sequence start>'")) {
+ return listItemColumn(problem, lines);
+ }
+ if (msg.contains("expected <block end>, but found '<block mapping
start>'")) {
+ return marks.size() > 1 ? mappingKeyColumn(marks.get(0), problem,
lines) : null;
+ }
+ if (msg.contains("mapping values are not allowed here")) {
+ return mappingValue(problem, lines);
+ }
+ if (msg.contains("found unknown escape character")) {
+ return unknownEscape(msg, problem, lines);
+ }
+ return null;
+ }
+
+ /** {@code found character '\t(TAB)' that cannot start any token}: the
line is indented with a tab. */
Review Comment:
**Doc nit: the `{@code}` names the wrong fragment of the snakeyaml message.**
The Javadoc says the detection signal is `found character '\t(TAB)' that
cannot start any token`, but the check at the next line tests `"(TAB) for
indentation"`. The actual snakeyaml 2.5 message is:
```
found character '\t(TAB)' that cannot start any token. (Do not use (TAB) for
indentation)
```
Both substrings appear in it, so the code is correct — but a reader
comparing the Javadoc with the `contains` call will suspect a copy-paste error.
The Javadoc should name the fragment the code actually checks:
```suggestion
/** {@code Do not use (TAB) for indentation}: the line is indented with
a tab. */
```
--
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]