Skip to content

Prevent formatter from throwing on malformed input with embed rules#382

Open
holodorum wants to merge 1 commit intokson-org:mainfrom
holodorum:embed-rules
Open

Prevent formatter from throwing on malformed input with embed rules#382
holodorum wants to merge 1 commit intokson-org:mainfrom
holodorum:embed-rules

Conversation

@holodorum
Copy link
Copy Markdown
Collaborator

The formatter parses with ignoreErrors = true, which can leave hidden AstNodeError nodes in a tree where hasErrors() still returns false. resolveEmbedBlocks called root.toKsonValue() directly, so those hidden errors surfaced as a ShouldNotHappenException that escaped format() instead of falling back to the original source. This only reproduced when embed block rules were configured.

Take a KsonValue in resolveEmbedBlocks instead of a KsonRoot, and have the caller source it from AstParseResult.ksonValue — which already catches the conversion exception and returns null. The new ksonValue != null guard is strictly stronger than the previous !hasErrors() check.

The formatter parses with `ignoreErrors = true`, which can leave hidden
`AstNodeError` nodes in a tree where `hasErrors()` still returns false.
`resolveEmbedBlocks` called `root.toKsonValue()` directly, so those
hidden errors surfaced as a `ShouldNotHappenException` that escaped
`format()` instead of falling back to the original source. This only
reproduced when embed block rules were configured.

Take a `KsonValue` in `resolveEmbedBlocks` instead of a `KsonRoot`, and
have the caller source it from `AstParseResult.ksonValue` — which
already catches the conversion exception and returns null. The new
`ksonValue != null` guard is strictly stronger than the previous
`!hasErrors()` check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant