CONSUME-AS-DATA-10: Contrast validate() with read()
What it demonstrates
Section titled “What it demonstrates”validate() returns {findings, doc, tree} and never throws, while read() hands back a typed Doc or throws ContractError on error-level findings.
Builds on: CONSUME-AS-DATA-01: Open the read() door for typed frontmatter
How it’s done
Section titled “How it’s done”A TypeScript program against the library API; inline comments show the resulting values and behavior.
// Collect everything, never throw:const { findings, doc, tree } = c.validate(src, { path: "decision.md" });findings.forEach(f => console.log(f.level, f.path, f.message));if (doc) doc.frontmatter.id; // doc present only when valid
// Or take the typed door and let errors stop you:try { const d = c.read(src, { path: "decision.md" }); }catch (e) { /* ContractError carries the error-level findings */ }Surfaces exercised
Section titled “Surfaces exercised”contract.validate(src,{path}) → {findings, doc, tree}Finding.level/.path/.messagecontract.read + ContractError