{"record":{"id":"c07644c0ce56f2da","repo":"remotion-dev/remotion","slug":"cannot-reorder-effect-source-index-not-found","errorCode":null,"errorMessage":"Cannot reorder effect: source index not-found","messagePattern":"Cannot reorder effect: source index not-found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/effect-operations.ts","lineNumber":596,"sourceCode":"} & EffectSourceStyleOptions): Promise<{\n\toutput: string;\n\tformatted: boolean;\n\teffectLabel: string;\n\tlogLine: number;\n}> =>\n\tPromise.resolve().then(() => {\n\t\tconst ast = parseAst(input);\n\t\tconst snapshots = captureEffectSourceSnapshots(ast);\n\t\tconst jsx = getJsx({action: 'reorder', ast, sequenceNodePath});\n\t\tconst attr = findEffectsAttr(jsx.attributes);\n\t\tif (!attr) {\n\t\t\tthrow new Error('Could not find effects on the target JSX element');\n\t\t}\n\n\t\tconst array = getEffectsArray(attr, 'reorder');\n\t\tconst elements = enumerateEffectArrayElements(array);\n\t\tif (fromIndex < 0 || fromIndex >= elements.length) {\n\t\t\tthrow new Error('Cannot reorder effect: source index not-found');\n\t\t}\n\n\t\tif (toIndex < 0 || toIndex >= elements.length) {\n\t\t\tthrow new Error('Cannot reorder effect: target index not-found');\n\t\t}\n\n\t\tconst target = elements[fromIndex];\n\t\tif (target.kind !== 'call') {\n\t\t\tthrow new Error(\n\t\t\t\t'Cannot reorder effect: source effect is not-call-expression',\n\t\t\t);\n\t\t}\n\n\t\ttrackOpeningElement({jsx, snapshots});\n\t\tif (fromIndex !== toIndex) {\n\t\t\tconst [moved] = array.elements.splice(fromIndex, 1);\n\t\t\tarray.elements.splice(toIndex, 0, moved as never);\n\t\t}","sourceCodeStart":578,"sourceCodeEnd":614,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-codemods/src/effect-operations.ts#L578-L614","documentation":"reorderEffect validates fromIndex against the enumerated effects array (enumerateEffectArrayElements) before moving. An index below zero or at/above the number of elements means the source effect to move does not exist, so it throws. A companion check validates toIndex ('target index not-found').","triggerScenarios":"reorderEffect with fromIndex < 0 or fromIndex >= effects.length — typically an effect index captured before effects were deleted, or an index counted on a different element.","commonSituations":"Drag-and-drop reorder in Studio after another effect was deleted making stored indices stale; hard-coded index in an automation script; array shrank because non-call entries were cleaned up.","solutions":["Clamp/recompute fromIndex against the current array length before calling","Re-enumerate effects on the current source and refresh both indices","Guard: if (fromIndex >= 0 && fromIndex < elements.length) before invoking"],"exampleFix":"// before\nreorderEffect({fromIndex: 5, toIndex: 0, ...}); // 2 effects exist\n// after\nconst i = Math.min(fromIndex, elements.length - 1); reorderEffect({fromIndex: i, toIndex: 0, ...});","handlingStrategy":"validation","validationCode":"const elements = enumerateEffectArrayElements(getEffectsArray(findEffectsAttr(jsx.openingElement.attributes)!, 'check'));\nif (fromIndex < 0 || fromIndex >= elements.length) throw new Error('fromIndex out of range');\nif (toIndex < 0 || toIndex >= elements.length) throw new Error('toIndex out of range');","typeGuard":"const inBounds = (i: number, len: number): i is number => Number.isInteger(i) && i >= 0 && i < len;","tryCatchPattern":"try { await reorderEffect({fromIndex, toIndex, input, sequenceNodePath}); } catch (e) { if ((e as Error).message.includes('source index not-found')) { /* refresh indices from current source and retry once */ } else throw e; }","preventionTips":["Recompute indices immediately before reordering — never cache across edits","Clamp UI drag targets to the current array length","Delete and reorder flows should share one fresh enumeration source"],"tags":["effects","index-out-of-range","reorder","validation"],"backgroundTag":"index-out-of-range","analyzedSha":"46a3a6bf13ca367376ff18bbb06dae2e87e0d068","analyzedAt":"2026-09-18T00:12:20.256Z","contentChangedAt":"2026-09-18T00:12:20.256Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}