Skip to content

Complete error message format consistency - add quotes to property names #105

Closed

Description

@simbo1905

Issue: Complete error message format consistency

Location: json-java21-jtd/src/main/java/json/java21/jtd/Jtd.java

Current Status: ✅ COMPLETED

Changes Made:

  • MISSING_REQUIRED_PROPERTY: 'missing required property: %s' → 'missing required property: '%s''
  • ADDITIONAL_PROPERTY_NOT_ALLOWED: 'additional property not allowed: %s' → 'additional property not allowed: '%s''

Pattern Established:

  • User-provided string values (type names, property names, enum values, discriminator values) get single quotes
  • JSON class names (JsonNumber, JsonString, etc.) and type keywords (boolean, string, etc.) do NOT get quotes
  • This matches the existing pattern used by VALUE_NOT_IN_ENUM, DISCRIMINATOR_MUST_BE_STRING, etc.

Result:
✅ All tests pass. Error message format is now consistent across the codebase.

This issue is now resolved.

Activity

  1. changed the title [-]Simplify enum deduplication logic in JtdPropertyTest[/-] [+]Complete error message format consistency - add quotes to property names[/+] on Sep 28, 2025
  2. simbo1905 commented on Jan 26, 2026

    @simbo1905
    OwnerAuthor

    Analysis of Current State (main branch after PR #117 merge)

    Finding: Issue Appears Already Completed ✅

    Looking at the current code in json-java21-jtd/src/main/java/json/java21/jtd/Jtd.java (lines 745-786), the error messages already follow the consistent pattern described in this issue:

    Error messages WITH single quotes around user-provided values:

    Error Type Template
    UNKNOWN_TYPE "unknown type: '%s'"
    VALUE_NOT_IN_ENUM "value '%s' not in enum: %s"
    MISSING_REQUIRED_PROPERTY "missing required property: '%s'"
    ADDITIONAL_PROPERTY_NOT_ALLOWED "additional property not allowed: '%s'"
    DISCRIMINATOR_MUST_BE_STRING "discriminator '%s' must be a string"
    DISCRIMINATOR_VALUE_NOT_IN_MAPPING "discriminator value '%s' not in mapping"

    Error messages WITHOUT quotes (correct - these report Java class names/keywords, not user values):

    Error Type Template
    EXPECTED_BOOLEAN "expected boolean, got %s"
    EXPECTED_STRING "expected string, got %s"
    etc.

    Test Coverage Verified

    Tests in TestValidationErrors.java confirm the quoted format:

    • Line 151: assertThat(...).contains("missing required property: 'age'");
    • Line 173: assertThat(...).contains("additional property not allowed: 'extra'");

    Recommendation

    This issue can be closed - the changes described in the issue body are already implemented in the current main branch. The pattern is consistent: user-provided values (property names, type names, enum values) get single quotes, while Java type keywords don't.

  3. simbo1905 commented on Nov 21, 2026

    @simbo1905
    OwnerAuthor

    Verified resolved on branch issue-168-port-jtd-esm-codegen (commit 13285c0).

    Full audit of every error-message site in json-java21-jtd/src/main/java/json/java21/jtd/Jtd.java:

    Error enum (Jtd.java:727-771) — every template checked, not just the two named in the issue:

    Quoted (user-provided string values):

    • UNKNOWN_TYPE (line 730): "unknown type: '%s'" — type name
    • VALUE_NOT_IN_ENUM (754): "value '%s' not in enum: %s" — enum value quoted, values list unquoted
    • MISSING_REQUIRED_PROPERTY (760): "missing required property: '%s'" — property name
    • ADDITIONAL_PROPERTY_NOT_ALLOWED (763): "additional property not allowed: '%s'" — property name
    • DISCRIMINATOR_MUST_BE_STRING (766): "discriminator '%s' must be a string" — discriminator key
    • DISCRIMINATOR_VALUE_NOT_IN_MAPPING (769): "discriminator value '%s' not in mapping" — discriminator value

    Unquoted (type keywords / Java class names — correct):

    • EXPECTED_BOOLEAN 733, EXPECTED_STRING 736, EXPECTED_TIMESTAMP 739, EXPECTED_INTEGER 742, EXPECTED_NUMERIC_TYPE 745, EXPECTED_ARRAY 748, EXPECTED_OBJECT 751, EXPECTED_STRING_FOR_ENUM 757 — placeholders receive JsonString/JsonNumber etc. class names.

    All usage sites conform: Jtd.java:149,168 pass property-name keys into quoted slots. Every %%s receiving instance.getClass().getSimpleName() (JtdSchema.java:130-521) is an unquoted Java class name slot; every scalar user value (type, property name, enum value, discriminator key/value) lands in a quoted slot.

    Compile-time messages in Jtd.java also consistent: quoted user values — unknown type name (:512), unknown key in type schema (:498), non-existent ref (:586?), property/optionalProperties key overlap (:~640), discriminator mapping keys (:627-686); unquoted keywords and Java class names elsewhere.

    Test coverage: TestValidationErrors.java asserts the quoted formats: line 151 "missing required property: 'age'", line 173 "additional property not allowed: 'extra'", line 101 "value 'yellow' not in enum", line 195 "discriminator 'type' must be a string", line 201 "discriminator value 'unknown' not in mapping", line 216 "unknown type: 'unknown-type'"; unquoted class-name formats asserted at lines 30-54 and 107-129.

    Tests: mvn -pl json-java21-jtd test → BUILD SUCCESS, Tests run: 451, Failures: 0, Errors: 0, Skipped: 0 (TestValidationErrors 9/9 green).

    Closing as fully resolved.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions