Mintplex-Labs/anything-llm · warning
Folder by that name already exists
Error message
Folder by that name already exists
What it means
Returned by POST /document/create-folder (admin/manager) when fs.existsSync(storagePath) is true — a folder OR file with that normalized name already exists under documentsPath. It is an explicit duplicate check, not an exception; the 500 status is misleading (409 Conflict would be correct).
Source
Thrown at server/endpoints/document.js:25
} = require("../utils/middleware/multiUserProtected");
const { validatedRequest } = require("../utils/middleware/validatedRequest");
const fs = require("fs");
const path = require("path");
function documentEndpoints(app) {
if (!app) return;
app.post(
"/document/create-folder",
[validatedRequest, flexUserRoleValid([ROLES.admin, ROLES.manager])],
async (request, response) => {
try {
const { name } = reqBody(request);
const storagePath = path.join(documentsPath, normalizePath(name));
if (!isWithin(path.resolve(documentsPath), path.resolve(storagePath)))
throw new Error("Invalid folder name.");
if (fs.existsSync(storagePath)) {
response.status(500).json({
success: false,
message: "Folder by that name already exists",
});
return;
}
fs.mkdirSync(storagePath, { recursive: true });
response.status(200).json({ success: true, message: null });
} catch (e) {
console.error(e);
response.status(500).json({
success: false,
message: `Failed to create folder: ${e.message} `,
});
}
}
);
View on GitHub (pinned to 3aec848f28)
Solutions
- Use a different folder name, or open the existing folder instead of creating a new one
- List the documents directory to confirm what collides — it may be a file with the same name
- Client-side: treat this exact message as a duplicate conflict, not a server fault
- Server improvement: return 409 with this body instead of 500 so callers can branch on status
Example fix
// before (server/endpoints/document.js)
response.status(500).json({ success: false, message: 'Folder by that name already exists' });
// after
response.status(409).json({ success: false, message: 'Folder by that name already exists' }); Defensive patterns
Strategy: validation
Validate before calling
// Check current folder names before creating
const existing = new Set(folders.map((f) => f.name.toLowerCase()));
if (existing.has(name.trim().toLowerCase())) { selectFolder(name); return; } // idempotent skip
await fetch('/document/create-folder', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name }) }); Prevention
- Disable the Create button during submission to prevent double-posts
- Match names case-insensitively against the fetched folder list first
- Treat this message as a duplicate conflict (semantically 409), not a server error
When it happens
Trigger: POST /document/create-folder with {name} that collides with any existing entry in the documents storage directory. existsSync matches files too, so naming a folder like an existing file also triggers it.
Common situations: Double-submitting the 'Create folder' button in the UI; retrying a request that timed out but actually succeeded; scripted folder provisioning re-running without idempotency checks.
Related errors
- Failed to create folder: ${e.message}
- Failed to move some files.
- Failed to move files.
- Internal Server Error
- QEMU directory not found: ${dir}\nContents of ${parent}: ${c
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/dec31410276c41d7.
Report an issue: GitHub.