Skip to content

Surface actual parse error in MergeYaml#6818

Open
timtebeek wants to merge 1 commit intomainfrom
merge-yaml-surface-parse-error
Open

Surface actual parse error in MergeYaml#6818
timtebeek wants to merge 1 commit intomainfrom
merge-yaml-surface-parse-error

Conversation

@timtebeek
Copy link
Member

Summary

  • When MergeYaml.parse() encountered a YAML parsing failure, the maybeParse method silently discarded the ParseError result (via a Yaml.Documents instanceof filter), producing only a generic "Could not parse as YAML" message
  • Now extracts the actual error from the ParseExceptionResult marker and includes it in the IllegalArgumentException, making failures diagnosable (e.g. SnakeYAML syntax errors, print-idempotence failures)
  • Removes the intermediate maybeParse method and consolidates logic into parse()

Test plan

  • All existing MergeYamlTest tests pass

When MergeYaml.parse() fails, the actual parsing error (stored in a
ParseExceptionResult marker on the ParseError) was being silently
discarded by the Yaml.Documents instanceof filter, resulting in
an unhelpful "Could not parse as YAML" message.

Now the ParseExceptionResult message is extracted and included in
the IllegalArgumentException, making it possible to diagnose the
root cause (e.g. SnakeYAML syntax errors, print-idempotence failures).
@timtebeek
Copy link
Member Author

We saw this somehow pass validation but fail during execution, so rewrote the logic to capture and forward any parse failure message.

@timtebeek timtebeek requested a review from MBoegers February 25, 2026 14:14
@timtebeek timtebeek added bug Something isn't working recipe Requested Recipe labels Feb 25, 2026
try {
incoming = MergeYaml.parse(yaml);
return true;
} catch (IllegalArgumentException e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels strange to have an exception to signal failure. Failure is nothing special its expected in validation.
Also, creating an exception causes stack walking to fill the stacktrace and JIT deopt, maybe not very strong arguments in our case but still.

We could omit the exception and instead return the parsing error or erroneous and check with instaceof?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or turn the parse into a validateParseable method and return a validation result insteadt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working recipe Requested Recipe

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants