Skip to content

👌 Include JSON location in $ref resolution errors#1736

Merged
chrisjsewell merged 2 commits into
masterfrom
schema-ref-error-location
Jun 30, 2026
Merged

👌 Include JSON location in $ref resolution errors#1736
chrisjsewell merged 2 commits into
masterfrom
schema-ref-error-location

Conversation

@chrisjsewell

@chrisjsewell chrisjsewell commented Jun 30, 2026

Copy link
Copy Markdown
Member

Summary

resolve_refs errors (circular / invalid / missing $ref, $ref-with-siblings) gave no indication of where the faulty reference lived, so on a non-trivial needs_schema_definitions users had to hunt through the whole config to find it. Other config errors already carry a schema name via get_schema_name (id[idx]); the global $ref-resolution pass was the gap.

This threads the JSON path of the current item through the recursive resolve_refs walk and appends it to each error message.

Before → after

Circular reference detected for 'type-impl'.
→ Circular reference detected for 'type-impl' (at $defs.type-impl.allOf[0]).

Reference 'not-exist' not found in definitions.
→ Reference 'not-exist' not found in definitions (at schemas[0].validate.local).

Invalid $ref value: 123, expected a string.
→ Invalid $ref value: 123, expected a string (at schemas[0].validate.local).

Invalid $ref value: type-impl, expected to start with '#/$defs/'.
→ Invalid $ref value: type-impl, expected to start with '#/$defs/' (at schemas[0].validate.local).

The path is the JSON location from the root of needs_schema_definitions (schemas[i]... or $defs.<name>...), inherently encoding which schema (by index) the $ref sits in. When there is no path (root), the suffix is omitted, so behaviour is unchanged for that degenerate case.

Notes

  • Snapshot-only test impact: the five ref_* config fixtures in tests/schema/__snapshots__/test_schema.ambr now include the location.

`resolve_refs` errors (circular / invalid / missing $ref) gave no
indication of *where* the faulty reference was, forcing users to hunt
through the whole `needs_schema_definitions`. Thread the JSON path of the
current item through the recursive walk and append it to each error, e.g.:

  Circular reference detected for 'type-impl'.
  -> Circular reference detected for 'type-impl' (at $defs.type-impl.allOf[0]).

  Reference 'type-spec' not found in definitions.
  -> Reference 'type-spec' not found in definitions (at schemas[0].select).

Other config errors already carry a schema name via `get_schema_name`;
this closes the gap for the global $ref-resolution pass.
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.37%. Comparing base (4e10030) to head (1dc9c49).
⚠️ Report is 301 commits behind head on master.

Files with missing lines Patch % Lines
sphinx_needs/schema/config_utils.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1736      +/-   ##
==========================================
+ Coverage   86.87%   89.37%   +2.49%     
==========================================
  Files          56       72      +16     
  Lines        6532    10551    +4019     
==========================================
+ Hits         5675     9430    +3755     
- Misses        857     1121     +264     
Flag Coverage Δ
pytests 89.37% <75.00%> (+2.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chrisjsewell chrisjsewell merged commit 6506ecf into master Jun 30, 2026
24 checks passed
@chrisjsewell chrisjsewell deleted the schema-ref-error-location branch June 30, 2026 21:01
@chrisjsewell chrisjsewell mentioned this pull request Jul 1, 2026
chrisjsewell added a commit that referenced this pull request Jul 1, 2026
Prepares the **8.2.0** release.

## Version bumps

- `sphinx_needs/__init__.py` → `8.2.0`
- `.github/workflows/docker.yaml` (`NEEDS_VERSION`) → `8.2.0`
- `docs/_static/tutorial_needs.json` regenerated with the new version

## Changelog

Rewrote the `Unreleased` section into a user-friendly `8.2.0` entry.
Reviewing every PR since v8.1.1 surfaced several that were missing from
the draft (notably the full variant-data feature set), so those are now
included and categorised.

The entry leads with the two headline features:

- **Variant data** — a dedicated narrative section tying together the
new variant-data tooling (#1715, #1716, #1721, #1737):
`needs_variant_data` / `needs_variant_data_file`, the inline `<{ ... }>`
field syntax, the `variant` role, and the `if` directive — with runnable
examples showing the shared `var` namespace across filters, fields,
prose, and whole blocks.
- **`network_back` schema validation** (#1731) — incoming-link
validation, letting coverage rules ("every requirement must be covered
by a test") be expressed once on the target.

Remaining changes are grouped into **Improvements** (#1632, #1717,
#1736, #1730, context7), **Deprecations** (`needs_filter_data`),
**Breaking changes** (Open-Needs removal, #1732), and **Bug fixes**
(#1727, #1371, #1564). Internal/test-only PRs were intentionally
omitted.

Docs build cleanly — all cross-references in the new section resolve
without warnings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---
_Generated by [Claude
Code](https://claude.ai/code/session_01HQwraRU189oRFK5j4yRiYo)_

---------

Co-authored-by: Claude <noreply@anthropic.com>
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.

2 participants