{"record":{"id":"b13ec9180031ea3f","repo":"remotion-dev/remotion","slug":"cannot-duplicate-effect-found-reason","errorCode":null,"errorMessage":"Cannot duplicate effect: ${found.reason}","messagePattern":"Cannot duplicate effect: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/effect-operations.ts","lineNumber":487,"sourceCode":"\t\t\tJSXAttribute,\n\t\t\t{\n\t\t\t\tarray: ArrayExpression;\n\t\t\t\tindices: Set<number>;\n\t\t\t\teffectLabels: string[];\n\t\t\t\tlogLines: number[];\n\t\t\t}\n\t\t>();\n\t\tfor (const {effectIndex, sequenceNodePath} of effects) {\n\t\t\tconst jsx = getJsx({action: 'duplicate', ast, sequenceNodePath});\n\t\t\tconst attr = findEffectsAttr(jsx.attributes);\n\t\t\tif (!attr) {\n\t\t\t\tthrow new Error('Could not find effects on the target JSX element');\n\t\t\t}\n\n\t\t\tconst array = getEffectsArray(attr, 'duplicate');\n\t\t\tconst found = findEffectCallExpression({attr, effectIndex});\n\t\t\tif (found.kind === 'error') {\n\t\t\t\tthrow new Error(`Cannot duplicate effect: ${found.reason}`);\n\t\t\t}\n\n\t\t\tconst group = effectsByAttribute.get(attr) ?? {\n\t\t\t\tarray,\n\t\t\t\tindices: new Set<number>(),\n\t\t\t\teffectLabels: [],\n\t\t\t\tlogLines: [],\n\t\t\t};\n\t\t\teffectsByAttribute.set(attr, group);\n\t\t\ttrackOpeningElement({jsx, snapshots});\n\t\t\tif (group.indices.has(effectIndex)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tgroup.indices.add(effectIndex);\n\t\t\tgroup.effectLabels.push(`${found.callee}()`);\n\t\t\tgroup.logLines.push(\n\t\t\t\tfound.call.loc?.start.line ?? jsx.loc?.start.line ?? 1,","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-codemods/src/effect-operations.ts#L469-L505","documentation":"duplicateEffects validates each requested effect via findEffectCallExpression, which returns a discriminated result. When the result is an error ({kind:'error'}), the reason (e.g. 'not-found', 'out-of-range', 'not-call-expression') is interpolated into this message and thrown. It means the effectIndex does not resolve to a usable effect call in the element's effects array.","triggerScenarios":"duplicateEffects/duplicateEffect called with an effectIndex that does not exist in the element's effects array, indexes a non-call element (spread/conditional), or refers to a stale index after the array was modified.","commonSituations":"Stale effect indexes captured in Studio state before the file changed out-of-band; counting effects from a different element than the one the nodePath resolves to; effects array containing non-call entries.","solutions":["Re-read the element and enumerate its effects array to get fresh indexes before calling","Verify effectIndex is within 0..effects.length-1 for the resolved element","Remove or normalize non-CallExpression entries in the effects array","Use the most recent effect listing (e.g. from the composition parse) as the index source"],"exampleFix":"// before\nduplicateEffect({effectIndex: 3, ...}); // array has 2 entries\n// after\nconst idx = effectsArray.length - 1; duplicateEffect({effectIndex: idx, ...});","handlingStrategy":"validation","validationCode":"const el = findJsxElementAtNodePath(parseAst(input), sequenceNodePath);\nconst arr = getEffectsArray(findEffectsAttr(el!.openingElement.attributes)!, 'check');\nif (effectIndex < 0 || effectIndex >= arr.elements.length) throw new Error('effectIndex out of range');","typeGuard":"const isValidEffectIndex = (n: number, len: number): boolean => Number.isInteger(n) && n >= 0 && n < len;","tryCatchPattern":"try { await duplicateEffect({effectIndex, input, sequenceNodePath}); } catch (e) { if ((e as Error).message.startsWith('Cannot duplicate effect:')) { /* refresh indices from a fresh parse and retry */ } else throw e; }","preventionTips":["Always derive effectIndex from a fresh parse of current source","Invalidate cached indices when the file changes","Keep effects arrays call-only to avoid ambiguous indices"],"tags":["effects","index","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"}