{"record":{"id":"694d89378c0b5a34","repo":"slidevjs/slidev","slug":"slide-no-does-not-exist-the-deck-has-data-sl","errorCode":null,"errorMessage":"Slide ${no} does not exist. The deck has ${data.slides.length} slides (1-${data.slides.length}).","messagePattern":"Slide (.+?) does not exist\\. The deck has (.+?) slides \\(1-(.+?)\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slidev/node/mcp/operations.ts","lineNumber":14,"sourceCode":"import type { LoadedSlidevData } from '@slidev/parser/fs'\nimport type { SlideInfo, SlidePatch, SourceSlideInfo } from '@slidev/types'\nimport * as parser from '@slidev/parser/fs'\nimport YAML from 'yaml'\nimport { updateFrontmatterPatch } from '../utils'\n\n/**\n * Resolve a rendered slide (1-based, as displayed in the presentation) or\n * throw a descriptive error.\n */\nexport function resolveSlide(data: LoadedSlidevData, no: number): SlideInfo {\n  const slide = data.slides[no - 1]\n  if (!slide)\n    throw new Error(`Slide ${no} does not exist. The deck has ${data.slides.length} slides (1-${data.slides.length}).`)\n  return slide\n}\n\nfunction getMarkdown(data: LoadedSlidevData, source: SourceSlideInfo) {\n  const md = data.markdownFiles[source.filepath]\n  if (!md)\n    throw new Error(`Markdown file not loaded: ${source.filepath}`)\n  return md\n}\n\nfunction assertNotEntryHeadmatter(data: LoadedSlidevData, source: SourceSlideInfo, action: string) {\n  if (source.filepath === data.entry.filepath && data.entry.slides.indexOf(source) === 0) {\n    throw new Error(\n      `Cannot ${action} the first slide of the entry file: its frontmatter is the deck headmatter (global configuration). `\n      + `Edit its content with the update tool instead, or operate on the following slides.`,\n    )\n  }\n}","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/slidevjs/slidev/blob/0d798ace5828966d9f77f62094d5f7a971ad98f7/packages/slidev/node/mcp/operations.ts#L1-L32","documentation":"Thrown by resolveSlide(data, no) when data.slides[no - 1] is falsy. Slides are addressed 1-based (matching presentation slide numbers); the error message echoes the valid 1..N range. Every MCP operation tool routes its slide-number argument through this guard.","triggerScenarios":"Calling any slide-scoped MCP tool (slidev-get-slide, slidev-update-slide, slidev-remove-slide, slidev-move-slide, slidev-goto-slide) with a number greater than data.slides.length, less than 1, or a number that became stale after a prior insert/remove/move shifted the deck.","commonSituations":"An agent edits the deck (insert/remove) and reuses an old slide number without re-listing; user passes a 0-based index by mistake; hidden/disabled slides shrink the visible count vs. what the caller assumed.","solutions":["Call slidev-list-slides again to refresh slide numbers after any insert/remove/move, then retry with a valid number.","Pass a number in the range 1..totalSlides reported by slidev-get-info.","If the caller holds stale state, re-fetch via ctx.getData() before indexing."],"exampleFix":"// before: stale number after a remove\nawait tools['slidev-remove-slide']({ no: 3 })\nawait tools['slidev-get-slide']({ no: 5 }) // deck now shorter -> throws\n\n// after: refresh, then index by the new layout\nconst slides = await tools['slidev-list-slides']({})\nconst last = slides.at(-1).no\nawait tools['slidev-get-slide']({ no: last })","handlingStrategy":"validation","validationCode":"function assertSlideNo(data: { slides: unknown[] }, no: number): void {\n  if (!Number.isInteger(no) || no < 1 || no > data.slides.length) {\n    throw new RangeError(`Slide no must be 1..${data.slides.length}, got ${no}`)\n  }\n}\n\n// before any tool call:\nconst data = await ctx.getData()\nassertSlideNo(data, requestedNo)","typeGuard":"function isValidSlideNo(no: unknown, total: number): no is number {\n  return typeof no === 'number'\n    && Number.isInteger(no)\n    && no >= 1\n    && no <= total\n}","tryCatchPattern":"try {\n  const slide = resolveSlide(data, no)\n} catch (e) {\n  if (e instanceof Error && /does not exist\\./.test(e.message)) {\n    // re-list and surface the valid range to the caller/agent\n    const total = data.slides.length\n    return { error: `invalid slide number; valid range is 1-${total}` }\n  }\n  throw e\n}","preventionTips":["After any insert/remove/move, call slidev-list-slides before reusing slide numbers.","Treat slide numbers as ephemeral; never cache them across mutations.","Always read totalSlides from slidev-get-info before constructing requests.","Prefer addressing slides by title or content match, then resolve to a number, in agent flows."],"tags":["mcp","slides","validation","bounds"],"backgroundTag":null,"analyzedSha":"0d798ace5828966d9f77f62094d5f7a971ad98f7","analyzedAt":"2026-08-12T17:10:56.221Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}