{"record":{"id":"ad2fed9b852a717e","repo":"remotion-dev/remotion","slug":"could-not-locate-the-folder-to-rename","errorCode":null,"errorMessage":"Could not locate the folder to rename","messagePattern":"Could not locate the folder to rename","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/studio-codemods/src/folder-source-edits.ts","lineNumber":497,"sourceCode":"\t\t\t? getFolder({\n\t\t\t\t\tfolderName: codeMod.folderName,\n\t\t\t\t\titems,\n\t\t\t\t\tparentName: codeMod.parentName,\n\t\t\t\t})\n\t\t\t: null;\n\tconst {newAst, changesMade} = applyCodemod({file: ast, codeMod});\n\tif (changesMade.length === 0) {\n\t\tthrow new Error(\n\t\t\t'Unable to calculate the changes needed for this file. Edit the file manually.',\n\t\t);\n\t}\n\n\tlet edits: SourceEdit[];\n\tif (codeMod.type === 'new-folder') {\n\t\tedits = getNewFolderSourceEdits({ast: newAst, input});\n\t} else if (codeMod.type === 'rename-folder') {\n\t\tif (folder === null) {\n\t\t\tthrow new Error('Could not locate the folder to rename');\n\t\t}\n\n\t\tedits = [\n\t\t\tgetJsxStringAttributeValueSourceEdit({\n\t\t\t\tattribute: getFolderNameAttribute(folder.node),\n\t\t\t\tinput,\n\t\t\t\tnewValue: codeMod.newName,\n\t\t\t}),\n\t\t];\n\t} else if (codeMod.type === 'delete-folder') {\n\t\tif (folder === null) {\n\t\t\tthrow new Error('Could not locate the folder to delete');\n\t\t}\n\n\t\tedits = [getDeleteFolderSourceEdit({input, located: folder})];\n\t} else {\n\t\tedits = getMoveSourceEdits({codeMod, input, items});\n\t}","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/remotion-dev/remotion/blob/46a3a6bf13ca367376ff18bbb06dae2e87e0d068/packages/studio-codemods/src/folder-source-edits.ts#L479-L515","documentation":"editFolderInSource in @remotion/studio-codemods edits a folder in the source of a composition. For a 'rename-folder' codemod it first resolves the folder node from the AST; if no folder node could be located (folder === null), it refuses to proceed with this error instead of guessing at edits. This is a lookup failure, not a parse failure.","triggerScenarios":"Calling editFolderInSource with a 'rename-folder' codeMod where the folder ID/name passed in the input does not match any folder node found in the parsed source AST, so folder resolution returns null.","commonSituations":"Renaming a folder in Remotion Studio after the underlying file was edited manually or reformatted so the folder node no longer matches; stale folder references in studio state pointing at a folder that was deleted or whose markup changed.","solutions":["Verify the folder still exists in the composition source file and that its name/id matches what the codemod input references.","Re-open/refresh the studio state so folder references are re-resolved from current source.","Re-parse the file and confirm the folder node is found before calling editFolderInSource (run the same lookup your pipeline uses).","If the file was hand-edited, revert or fix the edit so the folder markup is intact, then retry the rename."],"exampleFix":"// before (folder id stale)\nawait editFolderInSource({input: src, codeMod: {type: 'rename-folder', folderId: 'old-id', newName: 'x'}});\n// after (resolve the real folder id first)\nconst folder = locateFolder(src, 'My Folder');\nif (!folder) throw new Error('Folder missing from source');\nawait editFolderInSource({input: src, codeMod: {type: 'rename-folder', folderId: folder.id, newName: 'x'}});","handlingStrategy":"validation","validationCode":"const folder = sourceFile && locateFolderNode(sourceFile, folderRef);\nif (!folder) throw new Error(`Folder \"${folderRef}\" not found in source; refresh state before rename`);","typeGuard":"const isFolderLocated = (f: unknown): f is LocatedFolder =>\n  Boolean(f) && typeof f === 'object' && 'node' in (f as object);","tryCatchPattern":"try {\n  await editFolderInSource({input, codeMod});\n} catch (e) {\n  if (e instanceof Error && e.message === 'Could not locate the folder to rename') {\n    console.warn('Folder missing; reloading studio state');\n    await refreshSourceState();\n  } else throw e;\n}","preventionTips":["Re-resolve folder references from the current file before each codemod run","Avoid concurrent manual edits to files a codemod will touch","Validate folder existence in source as a pre-step in your pipeline"],"tags":["ast","codemod","folder","lookup-failed"],"backgroundTag":"entity-not-found","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"}