fix: add file-context to generator parse errors#688
fix: add file-context to generator parse errors#688hagemaruwu wants to merge 3 commits intonodejs:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
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
astandmetadatagenerators with contextual messages that include the relevant file path/basename. - Include
file.pathin 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.
src/generators/metadata/generate.mjs
Outdated
| } catch (err) { | ||
| const path = | ||
| input?.file?.path ?? input?.file?.basename ?? '<unknown file>'; | ||
| const message = `Failed to parse metadata for ${path}: ${err.message ?? err}`; |
src/generators/ast/generate.mjs
Outdated
| file: { stem: vfile.stem, basename: vfile.basename, path }, | ||
| }); | ||
| } catch (err) { | ||
| const message = `Failed to process ${path}: ${err.message ?? err}`; |
| message: 'Failed to parse metadata for fs.md: PARSE_ERROR', | ||
| cause: error, | ||
| }); | ||
| }); |
|
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. |
Description
This PR improves error reporting for parallel generator failures so reviewers can immediately identify which file caused a crash.
Changes included:
AST generator now includes file.path in the returned file metadata.
AST processChunk wraps parsing and file read failures with a contextual message that includes the path.
Metadata processChunk wraps parseApiDoc failures with file context using a safe fallback chain:
path -> basename -> .
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:
Full test suite
node --run test
Formatting
node --run format:check
Lint
node --run lint
New unit tests for this change
These assert wrapped error message content and preserved cause.
Related Issues
Check List
node --run testand all tests passed.node --run format&node --run lint.