{"record":{"id":"beeb5b48704aacad","repo":"remotion-dev/remotion","slug":"a-folder-cannot-be-moved-inside-itself","errorCode":null,"errorMessage":"A folder cannot be moved inside itself","messagePattern":"A folder cannot be moved inside itself","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/recast-mods.ts","lineNumber":695,"sourceCode":"\t\t\t: null;\n\tconst destinationParentFolderName =\n\t\ttransformation.destination.type === 'root'\n\t\t\t? null\n\t\t\t: transformation.destination.type === 'folder'\n\t\t\t\t? [\n\t\t\t\t\t\ttransformation.destination.parentName,\n\t\t\t\t\t\ttransformation.destination.folderName,\n\t\t\t\t\t]\n\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t.join('/')\n\t\t\t\t: (target as unknown as LocatedItem).parentFolderName;\n\tif (\n\t\tsourceFolderPath !== null &&\n\t\tdestinationParentFolderName !== null &&\n\t\t(destinationParentFolderName === sourceFolderPath ||\n\t\t\tdestinationParentFolderName.startsWith(`${sourceFolderPath}/`))\n\t) {\n\t\tthrow new Error('A folder cannot be moved inside itself');\n\t}\n\n\tif (transformation.source.type === 'folder') {\n\t\tconst sourceFolderName = transformation.source.folderName;\n\t\tif (\n\t\t\tfolders.some(\n\t\t\t\t(folder) =>\n\t\t\t\t\tfolder.node !== sourceItem.node &&\n\t\t\t\t\tfolder.name === sourceFolderName &&\n\t\t\t\t\tfolder.parentFolderName === destinationParentFolderName,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`A folder named \"${sourceFolderName}\" already exists in the destination`,\n\t\t\t);\n\t\t}\n\t}\n","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/remotion-dev/remotion/blob/a6a7485a9aeb04219510fbe4874f8941486424df/packages/studio-codemods/src/recast-mods.ts#L677-L713","documentation":"When moving a folder, the codemod guards against placing a folder into its own subtree, which would create an invalid/cyclic structure. If the computed destination parent path equals the source folder path or is nested under it (destinationParentFolderName starts with 'sourceFolderPath/'), this error is thrown instead of corrupting the AST.","triggerScenarios":"Calling applyCodemod with source {type: 'folder', parentName, folderName} and a destination ('folder' or a before/after target whose parent resolves to that same folder path or any descendant of it), e.g. moving folder 'A' into 'A/Sub' or reordering relative to an item inside 'A'.","commonSituations":"Dragging a folder onto one of its own children or itself in the studio; scripted transformations computing destination paths programmatically without cycle checks.","solutions":["Verify the destination path is not the source folder or nested inside it before calling applyCodemod","Treat a drop of a folder onto its own subtree as a no-op in the caller","Adjust the destination to a sibling location outside the source subtree"],"exampleFix":"// before\nmove({source: {type: 'folder', parentName: null, folderName: 'A'}, destination: {type: 'folder', parentName: 'A', folderName: 'Sub'}});\n// after\nmove({source: {type: 'folder', parentName: null, folderName: 'A'}, destination: {type: 'folder', parentName: null, folderName: 'B'}}); // outside A","handlingStrategy":"validation","validationCode":"const srcPath = [src.parentName, src.folderName].filter(Boolean).join('/');\nconst dstPath = [dest.parentName, dest.folderName].filter(Boolean).join('/');\nif (srcPath && dstPath && (dstPath === srcPath || dstPath.startsWith(srcPath + '/'))) return; // no-op, guard before calling","typeGuard":"const movesIntoItself = (srcPath: string | null, dstPath: string | null) => srcPath !== null && dstPath !== null && (dstPath === srcPath || dstPath.startsWith(`${srcPath}/`));","tryCatchPattern":"try {\n  await applyCodemod({transformation});\n} catch (e) {\n  if (String(e) === 'Error: A folder cannot be moved inside itself') return {changesMade: []}; // treat as intentional no-op\n  throw e;\n}","preventionTips":["Always compare source folder path against destination parent path before moving","In drag-drop UIs, disallow dropping a folder onto itself or its descendants","Compute destination paths with the same join(parentName, folderName) logic the codemod uses"],"tags":["codemod","validation","folder"],"backgroundTag":"invalid-move-operation","analyzedSha":"a6a7485a9aeb04219510fbe4874f8941486424df","analyzedAt":"2026-09-02T16:25:19.997Z","contentChangedAt":"2026-09-02T16:25:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}