Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-lions-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@neuledge/context": patch
---

Ignore non-string `title`/`description` frontmatter values when parsing docs. Previously a frontmatter field that parsed to a non-string (e.g. an object) propagated into the document title and broke package building with "Too few parameter values were provided". Such values now fall back to the derived title instead of crashing the build.
21 changes: 21 additions & 0 deletions packages/context/src/build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ Install the package.
expect(result.frontmatter.description).toBe("Learn how to get started");
});

it("ignores non-string frontmatter title (malformed YAML)", () => {
// Svelte 5's docs use unquoted titles like `{let/const ...}` that YAML
// parses into an object, which must not leak into docTitle (it would break
// SQLite parameter binding with "Too few parameter values were provided").
const source = `---
title: {let/const ...}
---

## Declaration tags

Some content about declaration tags.
`;

const result = parseMarkdown(source, "docs/declaration-tags.md");

expect(result.frontmatter.title).toBeUndefined();
// docTitle falls back to the filename-derived title
expect(typeof result.sections[0]?.docTitle).toBe("string");
expect(result.sections[0]?.docTitle).toBe("declaration-tags");
});

it("chunks content by h2 sections", () => {
const source = `---
title: Routing
Expand Down
10 changes: 9 additions & 1 deletion packages/context/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ function extractFrontmatter(tree: Root): DocFrontmatter {
if (!yamlNode) return {};

try {
return parseYaml(yamlNode.value) as DocFrontmatter;
// Validate types rather than blindly casting: malformed frontmatter can
// parse title/description into non-strings (e.g. a bare value the YAML
// parser reads as a map), which later breaks SQLite parameter binding.
const data = parseYaml(yamlNode.value) as Record<string, unknown> | null;
return {
title: typeof data?.title === "string" ? data.title : undefined,
description:
typeof data?.description === "string" ? data.description : undefined,
};
} catch {
return {};
}
Expand Down
Loading