Skip to content

fix: parse errors show meaningful messages instead of internal 'fail' label#1022

Merged
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:fix/parse-error-messages
Jun 24, 2026
Merged

fix: parse errors show meaningful messages instead of internal 'fail' label#1022
stephenamar-db merged 1 commit into
databricks:masterfrom
He-Pin:fix/parse-error-messages

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

fix: parse errors show meaningful messages instead of internal "fail" label

Motivation

Parse errors exposed fastparse's internal combinator name "fail" (e.g., Expected fail:1:12), which is meaningless to users. Root cause: several parser rules used bare Fail instead of Fail.opaque("descriptive message").

Modification

  • Parser.scala: Replaced 5 bare Fail with descriptive Fail.opaque(...):
    • String literal parsing → "string literal"
    • Verbatim string (@) → "verbatim string literal (@\" or @')"
    • Expression parsing → "expression"
  • Updated 2 golden files, added 2 error tests.

Result

Input sjsonnet (before) sjsonnet (after)
local x = ; x Expected fail:1:12 Expected expression:1:12
@hello Expected fail:1:2 Expected verbatim string literal
{a: } Expected fail:1:6 Expected expression:1:6

… label

Motivation:
Parse errors exposed fastparse's internal combinator name "fail"
(e.g., "Expected fail:1:12"), which is meaningless to users.

Root cause: Several parser rules used bare `Fail` instead of
`Fail.opaque("descriptive message")`, causing fastparse to use
the default "fail" label in error messages.

Fix: Replace bare `Fail` with descriptive `Fail.opaque(...)`:
- String literal parsing: "string literal"
- Verbatim string (@): "verbatim string literal (@\" or @')"
- Expression parsing: "expression"

Result:
- Before: "Expected fail:1:12, found ..."
- After:  "Expected expression:1:12, found ..."

Also includes error test files for format %c validation (from PR databricks#1015).

Cross-implementation comparison (local x = ; x):
| Implementation | Error message |
|---|---|
| C++ jsonnet | "unexpected: \";\" while parsing terminal" |
| go-jsonnet | "Unexpected: \";\" while parsing terminal" |
| sjsonnet (before) | "Expected fail:1:12" |
| sjsonnet (after) | "Expected expression:1:12" ✅ |
@stephenamar-db stephenamar-db merged commit 9e81880 into databricks:master Jun 24, 2026
5 checks passed
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.

2 participants