Skip to content

YAML parse errors in frontmatter crash validation run instead of reporting per-file #86

@mindsocket

Description

@mindsocket

Summary

When a file has invalid YAML in its frontmatter block (e.g. markdown content between --- delimiters), gray-matter throws a YAMLException. This exception propagates unhandled and crashes the entire validate run rather than being caught and reported as a validation error on that specific file.

Expected behaviour

The file is reported as a validation error (e.g. YAML parse error: <reason>) in the normal validation output, and validation continues for the rest of the space.

Actual behaviour

The process throws and exits with a stack trace, producing no validation summary at all.

Reproduction

A file with an opening --- followed by markdown content that is syntactically invalid YAML (e.g. bold syntax **text**) will trigger this. Example frontmatter:

---
## Summary

**Key contacts**: Alice (Constituency A), Bob (Constituency B).

gray-matter interprets everything up to the closing --- as YAML. The ** syntax is not valid YAML and triggers a YAMLException.

Stack trace (excerpt)

YAMLException: end of the stream or a document separator is expected at line 6, column 17

Notes

The fix is to wrap the per-file gray-matter parse call in a try/catch and surface the error as a structured validation failure on that file path, consistent with how schema validation errors are reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions