Skip to content

fix: unify and improve error-message quality across sjsonnet#1010

Open
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:worktree-error-message-consistency
Open

fix: unify and improve error-message quality across sjsonnet#1010
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:worktree-error-message-consistency

Conversation

@He-Pin

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

Copy link
Copy Markdown
Contributor

Motivation

Error messages across sjsonnet were inconsistent: some included
std.<name> prefixes, some did not; some leaked .getClass output;
some produced misleading or generic messages. This made debugging
Jsonnet programs harder and diverged from go-jsonnet's style.

Modification

  • Unify error-message construction via a single error-formatting path
    in Error.scala.
  • Add actual-value context to removeAt, codepoint, and
    flattenArrays errors.
  • Eliminate .getClass leaks from error messages.
  • Align error prefixing and formatting with go-jsonnet conventions.

Result

More informative, consistent error messages across the stdlib.
Improved debuggability for users. All tests pass on JVM / JS / Wasm /
Native / Graal.

References

@He-Pin He-Pin marked this pull request as draft June 20, 2026 09:48
He-Pin added a commit to He-Pin/sjsonnet that referenced this pull request Jun 20, 2026
Motivation:
The std namespace in Jsonnet is always lowercase. PR databricks#1010 incorrectly
capitalized it as Std.* in error messages during the capitalization
unification.

Modification:
Replace all Std.* references with std.* in error messages, golden test
files, and test assertions.

Result:
Error messages correctly reference std.* functions with lowercase namespace,
matching the Jsonnet language specification.
@He-Pin He-Pin marked this pull request as ready for review June 20, 2026 10:07
@He-Pin He-Pin marked this pull request as draft June 20, 2026 10:10
@He-Pin He-Pin force-pushed the worktree-error-message-consistency branch from b7856cf to 72a3dcd Compare June 20, 2026 10:20
@He-Pin He-Pin marked this pull request as ready for review June 20, 2026 10:24
@He-Pin He-Pin force-pushed the worktree-error-message-consistency branch 2 times, most recently from ec7a543 to ce15b64 Compare June 20, 2026 12:13
@He-Pin He-Pin changed the title fix: unify error-message capitalization across sjsonnet fix: unify and improve error-message quality across sjsonnet Jun 20, 2026
@He-Pin He-Pin force-pushed the worktree-error-message-consistency branch from ce15b64 to 82e7c9c Compare June 20, 2026 12:41
Motivation:
Error messages had inconsistent casing, missing context (function name,
parameter name, actual values), and in some cases exposed Java internals
(.getClass instead of .prettyName). This made debugging Jsonnet programs
frustrating.

Modification:
1. Capitalization: Every error message starts with a capital letter,
   while preserving exact casing for stdlib identifiers (assertEqual,
   manifestYamlStream, quote_keys, keyF).

2. Function context: Added std.<functionName>: prefix to ~40 messages
   across ArrayModule, SetModule, ManifestModule, MathModule,
   StringModule, and Format.scala.

3. Actual values: Replaced .getClass with .prettyName for readable
   type names. Added actual values to removeAt (idx + array length),
   codepoint (string length), and flattenArrays (element types).

4. Clarity: Rewrote confusing messages:
   - flattenArrays: "Binary operator +" → "cannot concatenate — arrays
     contain incompatible types"
   - validateSet: "Set operation on X was called with a non-set" →
     "second argument must be a sorted array without duplicates"
   - Format: "at N" → "at position N" for clarity

5. Removed Java internals: .getClass → .prettyName in ManifestModule
   (3 locations), .getClass → ujsonTypeName() in manifestXmlJsonml.

Result:
All ~95 error messages now include function context, use readable type
names, and start with a capital letter. Stdlib identifiers retain their
documented casing. 83 files changed (13 source + 37 golden + 7 test).
@He-Pin He-Pin force-pushed the worktree-error-message-consistency branch from 82e7c9c to 41ce83e Compare June 20, 2026 13:04
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