Skip to content

Include page path in PageData.vars error messages#242

Open
bcomnes wants to merge 5 commits intomasterfrom
fix/vars-getter-error-messages
Open

Include page path in PageData.vars error messages#242
bcomnes wants to merge 5 commits intomasterfrom
fix/vars-getter-error-messages

Conversation

@bcomnes
Copy link
Copy Markdown
Owner

@bcomnes bcomnes commented Apr 18, 2026

Closes #233

When a page vars module throws (syntax error, missing import, runtime exception at access time), the vars getter re-threw the error with no context about which page caused it. On a large site with pages spanning many directories, finding the broken page required manually bisecting the whole tree.

This wraps the getter body in a try/catch and re-throws with the page path included in the message:

Failed to resolve vars for page "2015/01/some-post": Cannot read properties of undefined

The original error is preserved as cause so nothing is lost. The fix only adds context to errors that were already being thrown; it does not change any behavior for pages that resolve successfully.

A side effect is that users who previously had to write defensive try/catch wrappers around every .vars access in global.data.js and templates will now get actionable errors instead of silently swallowed ones.

When a page's vars module throws (syntax error, missing dependency,
runtime error), the vars getter propagated a bare error with no
indication of which page failed. In global.data.js and templates,
this forced users to wrap every .vars access in try/catch and
silently swallow errors, hiding which page was broken.

The getter now catches any error at access time and re-throws with
the page path included in the message, making it easy to locate the
offending page without bisecting a large site.
Copilot AI review requested due to automatic review settings April 18, 2026 17:56
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 18, 2026

Coverage Report for CI Build 24619532678

Coverage remained the same at 91.469%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 15 of 15 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 4077
Covered Lines: 3811
Line Coverage: 93.48%
Relevant Branches: 647
Covered Branches: 510
Branch Coverage: 78.83%
Branches in Coverage %: Yes
Coverage Strength: 74.84 hits per line

💛 - Coveralls

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves debuggability of page variable resolution by adding page path context to errors thrown from the PageData.vars getter, making it easier to identify which page’s vars module caused a failure during builds.

Changes:

  • Wrapped PageData.vars getter in try/catch to intercept resolution/merge failures.
  • Re-threw a new error whose message includes pageInfo.path, preserving the original failure as cause.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/build-pages/page-data.js
@bcomnes
Copy link
Copy Markdown
Owner Author

bcomnes commented Apr 18, 2026

Acknowledged comment 3105591230. Declining to add tests in this PR for the following reason: testing the vars getter error path requires #initialized to be true, which is a private field only set by PageData.init(). init() performs file I/O and ESM module resolution, so unit-testing the error-wrapping path would require either a full integration fixture or hacking internal state via a subclass (which JS private fields prevent). That test infrastructure is a separate concern from this diagnostic improvement. Leaving it for a dedicated test PR if the error path becomes important to regression-test.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/build-pages/page-data.js Outdated
bcomnes and others added 2 commits April 18, 2026 12:52
Covers the two uninitialized-access paths: one where pageInfo has a path
(error message should include it) and one where it does not (fallback to
'<unknown page>'). Both guard against regressing the page-context diagnostic
improvement added in the vars getter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/build-pages/page-data.js Outdated
Comment thread lib/build-pages/page-data.test.js
bcomnes and others added 2 commits April 18, 2026 19:49
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bcomnes
Copy link
Copy Markdown
Owner Author

bcomnes commented Apr 19, 2026

This looks good to land.

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.

Improve PageData.vars getter error messages and resilience

3 participants