Skip to content

Improve error message when a schema has duplicated anchors #321

@jviotti

Description

@jviotti

The current one sucks. Check this out:

$ cat schema.json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/my-schema",
  "properties": {
    "foo": {
      "$anchor": "test"
    },
    "bar": {
      "$anchor": "test"
    }
  }
}

$ jsonschema inspect schema.json
error: Schema identifier already exists: https://example.com/my-schema#test

We should at the very least print the locations that result in the collision?

Might involve improving the exceptions getting thrown from this at Core while framing: https://github.com/sourcemeta/core/blob/d15c45c2dabb7418584dc5f23b22301e30ae4172/src/core/jsonschema/frame.cc#L4.

Maybe we need to have a different kind of exception for duplicated URI entries that take the current URI and the last location where the same URI was known to be registered at. With that information, we can construct a nice error message here

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