Claus Ibsen created CAMEL-25323:
-----------------------------------
Summary: camel-dataweave - unconverted DataWeave fails silently or
points at the generated DataSonnet; add an executed test corpus
Key: CAMEL-25323
URL: https://issues.apache.org/jira/browse/CAMEL-25323
Project: Camel
Issue Type: Bug
Reporter: Claus Ibsen
DataWeave scripts ({{.dwl}} or inline {{%dw}}) are translated to DataSonnet
when the route starts (CAMEL-23530). When the translator cannot handle
something, the user does not find out properly:
* The parser skips tokens it does not understand and skips missing brackets
without an error ({{DataWeaveParser.expect()}} and the {{parsePrimary}}
fallback). Only {{match}} and "unexpected token" are counted as "could not
convert".
* When something is not converted, the route still starts.
{{DatasonnetLanguage.convertDataWeave}} only logs a WARN and that part becomes
{{null}}. Example: {{payload.name match \{ case "bob" -> 1 else -> 0 \}}}
silently returns {{\{"k":null\}}}.
* When the translated script does fail, the error refers to a line and column
in the generated DataSonnet, which the user never wrote, e.g. {{Problem
parsing: Expected ")":6:21, found "$) null, b"}} for {{payload.items filter
($.qty > 1)}}.
* The 55 tests in {{DataWeaveConverterTest}} only check that the output
contains certain text ({{assertTrue(result.contains(...))}}). None of them run
the generated DataSonnet, which is how the bugs in the follow-up issue got
through.
Proposal:
# By default, fail at route start when any part could not be converted. The
message should name the DataWeave line, the construct, and a hint (e.g. "match
is not supported, rewrite as if/else"). Keep the lenient behaviour only as an
explicit option.
# Make the parser strict: a missing token or an unknown token is an error with
the DataWeave line and column, not something to skip.
# Where possible, also report DataSonnet runtime errors with the original
DataWeave location.
# Add a test set that runs end to end: one case per file with the {{.dwl}}
script, an input message and the expected output, run through camel-datasonnet.
Use it to cover the follow-up fixes.
_Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)