From cdd9a7d0e2b2153cec280f6f191e13d80c2dbb7c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 30 May 2026 19:42:19 +0000 Subject: [PATCH] fix(context): ignore non-string frontmatter title/description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some docs (e.g. Svelte 5's template-syntax pages) have unquoted YAML frontmatter titles like `{@render ...}` or `{let/const ...}` that the YAML parser reads as a flow-mapping object rather than a string. That object propagated into a section's docTitle and was then passed to a better-sqlite3 prepared statement as a positional argument, where it was interpreted as a named-parameters bind object — leaving fewer values than `?` placeholders and crashing the build with "Too few parameter values were provided". extractFrontmatter now keeps title/description only when they are strings, falling back to the filename-derived title otherwise. This unblocks publishing svelte@5.56.0 (and similarly-formatted docs). https://claude.ai/code/session_01Dk6cdQKeX3Lr1eDoL1uTXM --- .changeset/curly-lions-cheer.md | 5 +++++ packages/context/src/build.test.ts | 21 +++++++++++++++++++++ packages/context/src/build.ts | 10 +++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .changeset/curly-lions-cheer.md diff --git a/.changeset/curly-lions-cheer.md b/.changeset/curly-lions-cheer.md new file mode 100644 index 0000000..7f9a267 --- /dev/null +++ b/.changeset/curly-lions-cheer.md @@ -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. diff --git a/packages/context/src/build.test.ts b/packages/context/src/build.test.ts index a0f7841..2e8cb9f 100644 --- a/packages/context/src/build.test.ts +++ b/packages/context/src/build.test.ts @@ -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 diff --git a/packages/context/src/build.ts b/packages/context/src/build.ts index 1651c44..96fceee 100644 --- a/packages/context/src/build.ts +++ b/packages/context/src/build.ts @@ -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 | null; + return { + title: typeof data?.title === "string" ? data.title : undefined, + description: + typeof data?.description === "string" ? data.description : undefined, + }; } catch { return {}; }