Skip to content

fix: add file-context to generator parse errors#688

Open
hagemaruwu wants to merge 3 commits intonodejs:mainfrom
hagemaruwu:fix/error-path-reporting
Open

fix: add file-context to generator parse errors#688
hagemaruwu wants to merge 3 commits intonodejs:mainfrom
hagemaruwu:fix/error-path-reporting

Conversation

@hagemaruwu
Copy link

@hagemaruwu hagemaruwu commented Mar 18, 2026

Description

This PR improves error reporting for parallel generator failures so reviewers can immediately identify which file caused a crash.

Changes included:

  1. AST generator now includes file.path in the returned file metadata.

  2. AST processChunk wraps parsing and file read failures with a contextual message that includes the path.

  3. Metadata processChunk wraps parseApiDoc failures with file context using a safe fallback chain:
    path -> basename -> .

  4. Error wrapping preserves the original failure through Error cause.

5.Added unit tests for AST and metadata error wrapping behavior, including fallback behavior.

When Piscina workers fail due to malformed Markdown or YAML, the error now points to the exact source file instead of a generic parser failure.

Validation

I validated this in three ways:

  1. Full test suite

    node --run test

  2. Formatting

    node --run format:check

  3. Lint

    node --run lint

  4. New unit tests for this change

      [generate.test.mjs]
      [generate.test.mjs]
    

These assert wrapped error message content and preserved cause.

Related Issues

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@hagemaruwu hagemaruwu requested a review from a team as a code owner March 18, 2026 10:19
Copilot AI review requested due to automatic review settings March 18, 2026 10:19
@vercel
Copy link

vercel bot commented Mar 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Mar 19, 2026 6:20am

Request Review

Copy link
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 generator error reporting in parallel processing by adding per-file context to parsing failures and preserving underlying errors via Error.cause, making it easier to identify which source file triggered a crash.

Changes:

  • Wrap errors in ast and metadata generators with contextual messages that include the relevant file path/basename.
  • Include file.path in AST generator output metadata.
  • Add unit tests validating the new error-wrapping behavior (and cause preservation) for AST and metadata generators.

Reviewed changes

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

File Description
src/generators/metadata/generate.mjs Wraps parseApiDoc errors with file-context and rethrows with cause.
src/generators/metadata/tests/generate.test.mjs Adds tests asserting wrapped metadata parse errors include filename and preserve cause.
src/generators/ast/generate.mjs Adds file.path to AST output and wraps read/parse failures with file-context + cause.
src/generators/ast/tests/generate.test.mjs Adds a test asserting wrapped AST read failures include filename and preserve cause.

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

} catch (err) {
const path =
input?.file?.path ?? input?.file?.basename ?? '<unknown file>';
const message = `Failed to parse metadata for ${path}: ${err.message ?? err}`;
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in bbc3ecf.

file: { stem: vfile.stem, basename: vfile.basename, path },
});
} catch (err) {
const message = `Failed to process ${path}: ${err.message ?? err}`;
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in bbc3ecf.

message: 'Failed to parse metadata for fs.md: PARSE_ERROR',
cause: error,
});
});
Copy link
Author

Choose a reason for hiding this comment

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

Fixed in bbc3ecf.

@avivkeller
Copy link
Member

This contradicts #672

@hagemaruwu
Copy link
Author

This contradicts #672

Hey Aviv, thanks for the feedback. I took another look and you’re right: with centralized handling in the CLI runner, the generator-level try/catch wrapping here was redundant.

I removed the local wrapping so errors bubble natively to the centralized path, and updated the related tests accordingly. Pushed in ff10c83 — please re-review when you get a chance.

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.

3 participants