{"record":{"id":"fb6fe6cc0495108e","repo":"remotion-dev/remotion","slug":"from-must-be-a-non-negative-integer","errorCode":null,"errorMessage":"from must be a non-negative integer","messagePattern":"from must be a non-negative integer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio-server/src/preview-server/routes/insert-element.ts","lineNumber":84,"sourceCode":"\t\texpectedFileState,\n\t\tfrom,\n\t\tposition,\n\t\toverwriteExisting,\n\t\tundoRedoNavigation,\n\t\tnewComposition,\n\t},\n\tentryPoint,\n\tremotionRoot,\n\tlogLevel,\n}) =>\n\twithSourceFileWriteQueue(async () => {\n\t\ttry {\n\t\t\tvalidateElementInstallPosition(position);\n\t\t\tif (\n\t\t\t\tfrom !== null &&\n\t\t\t\t(!Number.isInteger(from) || !Number.isFinite(from) || from < 0)\n\t\t\t) {\n\t\t\t\tthrow new Error('from must be a non-negative integer');\n\t\t\t}\n\n\t\t\tconst installationMode =\n\t\t\t\telement.installationMode === null\n\t\t\t\t\t? 'wrapped'\n\t\t\t\t\t: element.installationMode;\n\t\t\tconst componentOwnsSequence =\n\t\t\t\tinstallationMode === 'component-owned-sequence';\n\t\t\tif (\n\t\t\t\tcomponentOwnsSequence &&\n\t\t\t\telement.initialProps !== null &&\n\t\t\t\t['from', 'durationInFrames', 'name'].some((prop) =>\n\t\t\t\t\tObject.hasOwn(element.initialProps ?? {}, prop),\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Component-owned Element initial props must not override from, durationInFrames, or name',\n\t\t\t\t);","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-server/src/preview-server/routes/insert-element.ts#L66-L102","documentation":"insertElementHandler inserts an element into a composition at an optional index `from`. The handler validates that `from`, when not null, is a finite non-negative integer. Anything else (negative numbers, floats, NaN, Infinity, non-numbers that slipped past typing) is rejected with this error before the install plan is computed.","triggerScenarios":"Sending an InsertElementRequest to the studio preview server with from = -1, a fractional value like 1.5, NaN/Infinity, or a malformed value from a client that bypasses typing.","commonSituations":"Client code computing the insert index as indexOf() returning -1 and passing it through unguarded; stale client state sending placeholder values; hand-rolled API calls to the studio server.","solutions":["Ensure the caller clamps the index: use Math.max(0, Math.round(index)) and pass null when no position is intended","Fix the client that passes -1 (e.g. from indexOf of a missing element) — convert -1 to null or 0","If calling the HTTP API directly, send a valid integer >= 0 or JSON null"],"exampleFix":"// before\nawait insertElement({from: children.indexOf(el)}); // -1 when missing\n// after\nconst idx = children.indexOf(el);\nawait insertElement({from: idx === -1 ? null : idx});","handlingStrategy":"validation","validationCode":"const validFrom = (from: number | null): number | null =>\n  from === null || (Number.isInteger(from) && Number.isFinite(from) && from >= 0) ? from : null;","typeGuard":"const isValidFrom = (from: unknown): from is number => typeof from === 'number' && Number.isInteger(from) && Number.isFinite(from) && from >= 0;","tryCatchPattern":"try {\n  await studio.insertElement({..., from});\n} catch (e) {\n  if (String(e).includes('from must be a non-negative integer')) {\n    await studio.insertElement({..., from: null}); // retry without position\n  } else throw e;\n}","preventionTips":["Convert -1 results from indexOf() to null before sending an insert request","Clamp and round computed indices: Math.max(0, Math.round(idx))","Validate request bodies client-side before calling the studio insert-element API"],"tags":["validation","api","studio-server"],"backgroundTag":"invalid-parameter","analyzedSha":"46a3a6bf13ca367376ff18bbb06dae2e87e0d068","analyzedAt":"2026-09-02T16:25:19.997Z","contentChangedAt":"2026-09-02T16:25:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}