Skip to content

fix: handle non-JSON files and invalid JSON - #977

Open
Devansh-567 wants to merge 1 commit into
json-schema-org:mainfrom
Devansh-567:fix/annotation-tests-json-handlings
Open

fix: handle non-JSON files and invalid JSON#977
Devansh-567 wants to merge 1 commit into
json-schema-org:mainfrom
Devansh-567:fix/annotation-tests-json-handlings

Conversation

@Devansh-567

Copy link
Copy Markdown

Summary

This PR improves the robustness of the repository's annotation validation scripts by handling two cases that currently result in uncaught exceptions.

  • bin/annotate-specification-links now uses version_urls.get(kind) instead of direct dictionary indexing, allowing the existing error-handling path for unknown specification kinds to execute.
  • bin/annotation-tests.ts now only processes .json files and reports invalid JSON with a readable per-file error instead of aborting with an uncaught exception.

Changes

bin/annotate-specification-links

  • Replace version_urls[kind] with version_urls.get(kind).

This ensures that unknown specification kinds are handled by the existing None check rather than raising a KeyError.

bin/annotation-tests.ts

  • Only process files ending with .json.
  • Wrap JSON.parse in a try/catch.
  • Report invalid JSON as a per-file validation error and continue validating the remaining files.

This prevents unrelated files (such as README.md or editor temporary files) or malformed JSON from terminating the validation script with an uncaught exception.

Why

Both changes make the validation scripts more resilient while preserving their behavior for valid inputs.

  • Unknown specification kinds now follow the existing error-reporting path instead of raising a KeyError.
  • Annotation test validation now ignores non-JSON files and reports malformed JSON with a clear error message instead of failing with a stack trace.

@Devansh-567
Devansh-567 requested a review from a team as a code owner July 10, 2026 11:01
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