{"record":{"id":"16882bb771448320","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-move-some-files-16882b","errorCode":null,"errorMessage":"Failed to move some files.","messagePattern":"Failed to move some files\\.","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/document.js","lineNumber":98,"sourceCode":"        Promise.all(movePromises)\n          .then(() => {\n            const unmovableCount = files.length - moveableFiles.length;\n            if (unmovableCount > 0) {\n              response.status(200).json({\n                success: true,\n                message: `${unmovableCount}/${files.length} files not moved. Unembed them from all workspaces.`,\n              });\n            } else {\n              response.status(200).json({\n                success: true,\n                message: null,\n              });\n            }\n          })\n          .catch((err) => {\n            console.error(\"Error moving files:\", err);\n            response\n              .status(500)\n              .json({ success: false, message: \"Failed to move some files.\" });\n          });\n      } catch (e) {\n        console.error(e);\n        response\n          .status(500)\n          .json({ success: false, message: \"Failed to move files.\" });\n      }\n    }\n  );\n}\n\nmodule.exports = { documentEndpoints };\n","sourceCodeStart":80,"sourceCodeEnd":112,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/document.js#L80-L112","documentation":"500 from the Promise.all .catch inside POST /document/move-files (admin/manager). Any individual move promise rejected: fs.rename failed (source missing, destination locked, EXDEV cross-device link) or the guard rejected with 'Invalid file location' because from/to escaped documentsPath. The detailed per-file err is only logged server-side ('Error moving file X to Y:'); the client gets this generic message.","triggerScenarios":"POST /document/move-files where some from/to path fails isWithin(documentsPath) (traversal), the source file no longer exists, the destination is a directory, or the documents storage spans filesystems so rename(2) returns EXDEV.","commonSituations":"Two clients moving the same file concurrently (source disappears); storage layout changed so documentsPath now crosses a mount point; unsanitized paths from API callers.","solutions":["Check the server console for 'Error moving file <from> to <to>:' lines — they carry the exact errno","Verify each source still exists under documentsPath and each destination folder exists","If EXDEV, consolidate document storage onto one filesystem, or replace fs.rename with copy+unlink","Re-fetch the document list and re-submit only the files that failed"],"exampleFix":"// before (server) — one failure aborts the whole batch report\nPromise.all(movePromises).then(...).catch(() => response.status(500)...);\n// after — settle individually and report partial success\nconst results = await Promise.allSettled(movePromises);\nconst failed = results.filter((r) => r.status === 'rejected');\nresponse.status(failed.length === movePromises.length ? 500 : 200)\n  .json({ success: failed.length === 0, message: failed.length ? `${failed.length} move(s) failed` : null });","handlingStrategy":"try-catch","validationCode":"// Verify sources exist and destinations are folders before moving\nconst docs = await fetchDocumentTree();\nfor (const { from, to } of files) {\n  if (!docs.has(from)) throw new Error(`Source missing: ${from}`);\n  if (!isDirectoryOf(docs, to)) throw new Error(`Destination folder missing: ${to}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const r = await fetch('/document/move-files', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ files }) });\n  if (r.status === 500) { await refreshDocumentTree(); retryMissing(files); } // reconcile and retry remainder once\n} catch (e) { console.error('move failed', e); }","preventionTips":["Keep documentsPath on a single filesystem to avoid EXDEV on rename","Re-fetch the document tree before bulk moves to drop vanished files","Server-side: prefer Promise.allSettled over Promise.all to report partial success"],"tags":["documents","fs-rename","file-move","http-500"],"backgroundTag":"fs-rename-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}