{"record":{"id":"4280f2d3d72228b9","repo":"remotion-dev/remotion","slug":"cannot-paste-effects-invalid-insertion-indices","errorCode":null,"errorMessage":"Cannot paste effects: invalid insertion indices","messagePattern":"Cannot paste effects: invalid insertion indices","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/effect-operations.ts","lineNumber":881,"sourceCode":"\t\t\tensureFrameHook({\n\t\t\t\tast,\n\t\t\t\tlocalNames,\n\t\t\t\tsequenceNodePath: targetSequenceNodePath,\n\t\t\t});\n\t\t}\n\n\t\tconst calls = effects.map((effect) =>\n\t\t\tmakeEffectCall({ast, effect, localNames}),\n\t\t);\n\t\tconst existingAttr = findEffectsAttr(jsx.attributes);\n\t\tif (\n\t\t\tinsertAtIndices !== null &&\n\t\t\t(type !== 'effects-additive' ||\n\t\t\t\tinsertAtIndices.length !== calls.length ||\n\t\t\t\tnew Set(insertAtIndices).size !== insertAtIndices.length ||\n\t\t\t\tinsertAtIndices.some((index) => !Number.isInteger(index) || index < 0))\n\t\t) {\n\t\t\tthrow new Error('Cannot paste effects: invalid insertion indices');\n\t\t}\n\n\t\tif (type === 'effects-replacing') {\n\t\t\tif (existingAttr) {\n\t\t\t\tjsx.attributes.splice(jsx.attributes.indexOf(existingAttr), 1);\n\t\t\t}\n\n\t\t\tif (calls.length > 0) {\n\t\t\t\tjsx.attributes.push(\n\t\t\t\t\tmakeEffectsAttr(b.arrayExpression(calls as never) as ArrayExpression),\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (calls.length === 0) {\n\t\t\tthrow new Error('Cannot paste effects: no effects were copied');\n\t\t} else if (insertAtIndices === null) {\n\t\t\tif (existingAttr) {\n\t\t\t\tgetEffectsArray(existingAttr, 'paste').elements.push(\n\t\t\t\t\t...(calls as ArrayExpression['elements']),","sourceCodeStart":863,"sourceCodeEnd":899,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-codemods/src/effect-operations.ts#L863-L899","documentation":"When pasting copied effects with explicit insert positions, insertAtIndices is only valid for type 'effects-additive' and must contain exactly one unique, non-negative integer per pasted effect. If insertAtIndices is non-null but any of these conditions fails, the paste is rejected with this error before any AST mutation.","triggerScenarios":"Calling pasteEffects with type 'effects-replacing' (or anything other than 'effects-additive') while also passing insertAtIndices; passing a different number of indices than effects; duplicate indices; negative or non-integer indices like -1, 1.5, NaN.","commonSituations":"UI paste handler that always supplies insertAtIndices from drag metadata even when the paste mode is 'replace'; mismatch between clipboard effect count and drop-slot count; index math producing fractional values.","solutions":["Only pass insertAtIndices when type is 'effects-additive'; pass null otherwise.","Ensure insertAtIndices.length === effects.length with no duplicates.","Sanitize indices: Number.isInteger(i) && i >= 0 for every entry.","Regenerate indices from the current target element's effect count."],"exampleFix":"// before\nawait pasteEffects({input, effects, type: 'effects-replacing', insertAtIndices: [0]});\n// after\nawait pasteEffects({input, effects, type: 'effects-replacing', insertAtIndices: null});","handlingStrategy":"validation","validationCode":"if (insertAtIndices !== null) {\n  const ok = type === 'effects-additive' &&\n    insertAtIndices.length === effects.length &&\n    new Set(insertAtIndices).size === insertAtIndices.length &&\n    insertAtIndices.every((i) => Number.isInteger(i) && i >= 0);\n  if (!ok) throw new Error('Bad insertAtIndices');\n}","typeGuard":"const isValidInsertIndices = (idx: unknown[] | null, n: number): idx is number[] =>\n  idx !== null && idx.length === n &&\n  new Set(idx).size === idx.length &&\n  idx.every((i) => Number.isInteger(i) && i >= 0);","tryCatchPattern":"try {\n  await pasteEffects(args);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Cannot paste effects: invalid insertion indices') {\n    // fall back to append: insertAtIndices: null\n  } else throw e;\n}","preventionTips":["Pass insertAtIndices only in effects-additive mode.","Generate one unique integer index per pasted effect.","Fall back to null (append) when indices cannot be validated."],"tags":["validation","argument-validation","studio"],"backgroundTag":"invalid-argument-value","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"}