Skip to content

[BUG]: propertyNames validation errors show "Invalid JSON Pointer" on $schema instead of the offending key #151

Closed

Description

@tarunagnihotri534

Bug Description

What's the problem?

When a schema uses propertyNames and a document has a key that fails it, the real error never shows up. Instead, the server reports "Invalid JSON Pointer" on the $schema line of the document, which is confusing because nothing is wrong with $schema.

Where it happens

src/features/diagnostics/SchemaValidationDiagnosticsProvider.ts: the validation error's instanceLocation is turned into a pointer with:

const pointer = decodeURIComponent(error.instanceLocation.slice(1));
const node = jsonDocument.findNodeAtPointer(pointer);

For propertyNames failures, the location seems to look like #*/123, so after slice(1) the pointer is */123. That isn't a valid JSON Pointer (it doesn't start with /), so findNodeAtPointer throws. The surrounding catch then attaches the exception message to /$schema.

The file also seems to have a toPointer helper that strips the leading *, but this line doesn't use it.

Steps to Reproduce

schema.json

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "propertyNames": { "pattern": "^[a-z]+$" }
}

doc.json

{
  "$schema": "./schema.json",
  "123": "value"
}

Open doc.json in the server.

Expected behavior

A diagnostic on the "123" key saying it doesn't match the pattern ^[a-z]+$.

Actual behavior

No diagnostic on "123". Instead there's an error on "./schema.json" with the message Invalid JSON Pointer.

How I checked

I found this while reviewing the code with an AI coding agent (Antigravity with
Gemini), then confirmed it myself. Opening doc.json with the schema above
shows "Invalid JSON Pointer" on the $schema line and nothing on "123".
Logging error.instanceLocation gives <paste what you actually saw>.

Suggested fix

When the error location starts with #*, strip the *, find the property node, and attach the diagnostic to the property's key node instead of letting the pointer lookup throw. Reusing the existing toPointer helper may be enough. I'd add tests for:

  • a key failing propertyNames produces a diagnostic on that key
  • the diagnostic is not reported on $schema
  • a document whose keys all pass propertyNames produces no diagnostics

Something else to flag

PR #148 (don't crash when $schema is an invalid IRI) touches nearby code, so I'm happy to rebase on it or wait for it to merge.

Impact

Medium - Feature works but has issues

I'd be glad to open a PR for this if that works for you. Thanks!

  • I have searched existing issues to avoid duplicates

Activity

  1. tarunagnihotri534 commented on Oct 11, 2026

    @tarunagnihotri534
    ContributorAuthor

    happy to work on this

  2. srivastava-diya commented on Oct 11, 2026

    @srivastava-diya
    Collaborator
    1. happy to work on this

    Hi! It's a request that please don't raise a PR until someone validates your issue and assigns it to you. Thanks.

  3. tarunagnihotri534 commented on Oct 11, 2026

    @tarunagnihotri534
    ContributorAuthor

    really sorry for this, i got this @srivastava-diya

  4. srivastava-diya commented on Oct 11, 2026

    @srivastava-diya
    Collaborator

    Logging error.instanceLocation gives <paste what you actually saw>

    This part was left as a placeholder, so i wonder if you've actually run it?

  5. srivastava-diya commented on Oct 11, 2026

    @srivastava-diya
    Collaborator

    I tried your example and the bug is present, the only diagnostic is "Invalid JSON Pointer" on the $schema value, and nothing shows on "123".

    I see you had already opened #153, so @jdesrosiers can decide whether to take it from that PR.

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