{"record":{"id":"2566c55cf741a712","repo":"slidevjs/slidev","slug":"the-before-after-anchor-must-be-a-different-sl","errorCode":null,"errorMessage":"The `before`/`after` anchor must be a different slide than `from`.","messagePattern":"The `before`/`after` anchor must be a different slide than `from`\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/slidev/node/mcp/operations.ts","lineNumber":176,"sourceCode":"\nexport interface MoveSlideResult {\n  moved: SlideInfo\n  anchor: SlideInfo\n  filepath: string\n  fileContent: string\n}\n\n/**\n * Move a slide before or after another slide within the same markdown file.\n */\nexport async function moveSlide(data: LoadedSlidevData, options: MoveSlideOptions): Promise<MoveSlideResult> {\n  const { from, before, after } = options\n  if ((before == null) === (after == null))\n    throw new Error('Specify exactly one of `before` or `after`.')\n\n  const anchorNo = (before ?? after)!\n  if (anchorNo === from)\n    throw new Error('The `before`/`after` anchor must be a different slide than `from`.')\n\n  const slide = resolveSlide(data, from)\n  const anchor = resolveSlide(data, anchorNo)\n\n  if (slide.source.filepath !== anchor.source.filepath) {\n    throw new Error(\n      `Cannot move a slide across markdown files: slide ${from} is in \"${slide.source.filepath}\" `\n      + `but slide ${anchorNo} is in \"${anchor.source.filepath}\" (imported with \\`src:\\`). `\n      + `Move it within its own file, or edit the \\`src:\\` imports in the entry file manually.`,\n    )\n  }\n\n  assertNotEntryHeadmatter(data, slide.source, 'move')\n  if (before != null)\n    assertNotEntryHeadmatter(data, anchor.source, 'insert a slide before')\n\n  const md = getMarkdown(data, slide.source)\n  const fromIdx = md.slides.indexOf(slide.source)","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/slidevjs/slidev/blob/0d798ace5828966d9f77f62094d5f7a971ad98f7/packages/slidev/node/mcp/operations.ts#L158-L194","documentation":"Thrown by moveSlide when anchorNo === from, i.e. the caller asked to move a slide before/after itself, which is a no-op and would produce an inconsistent splice. Caught before any file mutation.","triggerScenarios":"Calling slidev-move-slide with before or after equal to from (e.g. move slide 3 before slide 3).","commonSituations":"A caller computes the anchor from the source position by mistake; an agent loops over candidate positions and accidentally passes the source's own number.","solutions":["Choose an anchor slide number different from from.","If the intent is to leave the slide in place, skip the moveSlide call entirely."],"exampleFix":"// before: anchor equals source\nawait tools['slidev-move-slide']({ from: 3, after: 3 }) // throws\n\n// after: pick a distinct anchor\nawait tools['slidev-move-slide']({ from: 3, after: 4 })","handlingStrategy":"validation","validationCode":"function anchorDistinct(from: number, anchor?: number): boolean {\n  return anchor != null && anchor !== from\n}\n\n// before moveSlide:\nconst anchorNo = before ?? after\nif (!anchorDistinct(from, anchorNo)) {\n  throw new Error('Anchor must differ from `from`.')\n}","typeGuard":"function isValidMove(\n  o: { from: number; before?: number; after?: number },\n): o is { from: number; before: number } | { from: number; after: number } {\n  const anchor = o.before ?? o.after\n  return anchor != null && anchor !== o.from\n}","tryCatchPattern":"try {\n  await moveSlide(data, { from, before, after })\n} catch (e) {\n  if (e instanceof Error && /anchor must be a different slide/.test(e.message)) {\n    return { error: 'No-op move: anchor equals source.' }\n  }\n  throw e\n}","preventionTips":["Compute the anchor from a different slide than `from`.","Skip the move call when source and target coincide.","In loops over candidate positions, filter out the source index before choosing an anchor."],"tags":["mcp","validation","move","arguments"],"backgroundTag":null,"analyzedSha":"0d798ace5828966d9f77f62094d5f7a971ad98f7","analyzedAt":"2026-08-12T17:10:56.221Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}