{"record":{"id":"b109f537c33e53ac","repo":"slidevjs/slidev","slug":"invalid-yaml-frontmatter-parsed-errors-map-e","errorCode":null,"errorMessage":"Invalid YAML frontmatter: ${parsed.errors.map(e => e.message).join('; ')}","messagePattern":"Invalid YAML frontmatter: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slidev/node/mcp/operations.ts","lineNumber":63,"sourceCode":" */\nexport async function applySlidePatch(\n  data: LoadedSlidevData,\n  no: number,\n  patch: SlidePatch,\n): Promise<SlidePatchResult> {\n  const slide = resolveSlide(data, no)\n  const source = slide.source\n\n  if (patch.content != null)\n    source.content = patch.content\n  if (patch.frontmatterRaw != null) {\n    if (patch.frontmatterRaw.trim() === '') {\n      source.frontmatterDoc = source.frontmatterStyle = undefined\n    }\n    else {\n      const parsed = YAML.parseDocument(patch.frontmatterRaw)\n      if (parsed.errors.length)\n        throw new Error(`Invalid YAML frontmatter: ${parsed.errors.map(e => e.message).join('; ')}`)\n      source.frontmatterDoc = parsed\n    }\n  }\n  if (patch.note != null)\n    source.note = patch.note\n  if (patch.frontmatter)\n    updateFrontmatterPatch(source, patch.frontmatter)\n\n  parser.prettifySlide(source)\n  const fileContent = await parser.save(getMarkdown(data, source))\n  return { slide, fileContent }\n}\n\nexport interface InsertSlideOptions {\n  /**\n   * Rendered slide number (1-based) after which the new slide is inserted.\n   * The new slide is inserted into the same markdown file as this slide.\n   */","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/slidevjs/slidev/blob/0d798ace5828966d9f77f62094d5f7a971ad98f7/packages/slidev/node/mcp/operations.ts#L45-L81","documentation":"Thrown inside applySlidePatch when patch.frontmatterRaw is non-empty and YAML.parseDocument(patch.frontmatterRaw) returns one or more errors. It surfaces the underlying YAML parser messages joined by '; ' so the caller can correct the syntax. Used by the raw-frontmatter update path.","triggerScenarios":"Calling slidev-update-slide (or applySlidePatch directly) with a frontmatterRaw string that is not valid YAML: bad indentation, duplicate keys, unquoted special characters, tabs for indentation, or a stray ':'.","commonSituations":"Hand-writing frontmatter with inconsistent indentation; pasting YAML with tabs instead of spaces; using unquoted values like yes/no/on/off that YAML coerces; malformed nested mappings.","solutions":["Validate the YAML locally before sending: YAML.parseDocument(raw).errors must be empty.","Use 2-space indentation and quote values containing ':', '#', or leading/trailing spaces.","Prefer the structured frontmatter patch object (object form) over frontmatterRaw when only changing known keys.","Run the raw block through a YAML linter/formatter (e.g. prettier with yaml plugin)."],"exampleFix":"// before: malformed raw frontmatter (tab indent)\nawait applySlidePatch(data, no, {\n  frontmatterRaw: 'layout: two-cols\\n\\ttransition: slide',\n})\n\n// after: valid 2-space YAML\nawait applySlidePatch(data, no, {\n  frontmatterRaw: 'layout: two-cols\\n  transition: slide',\n})","handlingStrategy":"validation","validationCode":"import YAML from 'yaml'\n\nfunction validateFrontmatterRaw(raw: string): void {\n  if (raw.trim() === '') return\n  const parsed = YAML.parseDocument(raw)\n  if (parsed.errors.length) {\n    throw new Error(`Invalid YAML: ${parsed.errors.map(e => e.message).join('; ')}`)\n  }\n}\n\n// before applySlidePatch:\nif (patch.frontmatterRaw != null) validateFrontmatterRaw(patch.frontmatterRaw)","typeGuard":"function isValidYaml(raw: string): boolean {\n  if (raw.trim() === '') return true\n  return YAML.parseDocument(raw).errors.length === 0\n}","tryCatchPattern":"try {\n  await applySlidePatch(data, no, { frontmatterRaw })\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Invalid YAML frontmatter')) {\n    // show parser errors to the user, keep the draft for editing\n    return { error: e.message, draft: frontmatterRaw }\n  }\n  throw e\n}","preventionTips":["Validate frontmatterRaw with YAML.parseDocument before sending.","Prefer the structured frontmatter object patch for known keys.","Use 2-space indentation; never tabs.","Quote values containing ': ', '#', or leading/trailing whitespace.","Lint YAML with prettier/yamllint in your editor."],"tags":["yaml","frontmatter","validation","mcp"],"backgroundTag":null,"analyzedSha":"0d798ace5828966d9f77f62094d5f7a971ad98f7","analyzedAt":"2026-08-12T17:10:56.221Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}