Skip to content

Error message is misleading when defining an attribute incorrectly in schema JSON #417

@cdisselkoen

Description

@cdisselkoen

Before opening, please confirm:

Bug Category

Schemas and Validation

Describe the bug

For the below schema, the reported error is

unknown field `baz`, expected one of `type`, `element`, `attributes`, `additionalAttributes`, `name`

This is misleading because baz is a completely valid field (attribute name), and changing baz to some other string (like the ones listed) will not fix the problem.

Instead, the issue is in the bar field. The set element type was listed as "Long" instead of { "type": "Long" }.

If you fix the set-element mistake, you see that a similar mistake was made in the baz field, but that one actually has a reasonable-ish error message once you fix the set-element mistake:

invalid type: string "Boolean", expected struct TypeOfAttribute

This actually points to the correct problem location ("Boolean"), and from this error message an end-user could probably decipher a hint that they need a JSON object instead of just the string "Boolean". (This error message itself could definitely be improved, too; for instance, we could suggest that you need { "type": ... } instead of using the cryptic term TypeOfAttribute; and we could even perhaps suggest { "type": "Boolean" } in this particular case.)

Expected behavior

A better error message -- at least one that points to the bar attribute instead of baz, and ideally a reasonable suggested fix. See above.

Reproduction steps

Try to parse the schema given below

Code Snippet

{ "": {
   "entityTypes": {
       "a": {
           "shape": {
               "type": "Record",
               "attributes": {
                    "foo": { "type": "Entity", "name": "b" },
                    "bar": { "type": "Set", "element": "Long" },
                    "baz": { "type": "Record", "attributes": { "z": "Boolean" } }
               }
           }
       },
       "b": {}
   }
} }

Log output

No response

Additional configuration

No response

Operating System

No response

Additional information and screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    papercutSmall annoyances in the Cedar SDK. Lower priority fixes than bugs. Smaller than a feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions