Mintplex-Labs/anything-llm · error

Failed to move files.

Error message

Failed to move files.

What it means

Outer synchronous catch for POST /document/move-files. Fires when setup fails before the move promises are even created — typically reqBody shape is wrong (files missing or not an array, so .filter/.map throws a TypeError) or the embedded-files lookup for the workspace throws (DB error). Distinct from error 683, which fires on async rename failures.

Source

Thrown at server/endpoints/document.js:104

                message: `${unmovableCount}/${files.length} files not moved. Unembed them from all workspaces.`,
              });
            } else {
              response.status(200).json({
                success: true,
                message: null,
              });
            }
          })
          .catch((err) => {
            console.error("Error moving files:", err);
            response
              .status(500)
              .json({ success: false, message: "Failed to move some files." });
          });
      } catch (e) {
        console.error(e);
        response
          .status(500)
          .json({ success: false, message: "Failed to move files." });
      }
    }
  );
}

module.exports = { documentEndpoints };

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Confirm the request is JSON with shape {files: [{from: 'a.pdf', to: 'sub/a.pdf'}, ...]}
  2. Check the server console — the caught exception (usually a TypeError) is printed with the stack
  3. Retry with a single-element files array to isolate the failing input
  4. If the console shows a DB error, resolve database connectivity first

Example fix

// before
await fetch('/document/move-files', { method: 'POST', body: JSON.stringify({ files: maybeFiles }) });
// after
if (!Array.isArray(maybeFiles) || maybeFiles.some((f) => !f?.from || !f?.to))
  throw new Error('files must be an array of {from, to}');
await fetch('/document/move-files', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ files: maybeFiles }) });
Defensive patterns

Strategy: validation

Validate before calling

// Enforce request shape before the call
if (!Array.isArray(files) || files.some((f) => typeof f?.from !== 'string' || typeof f?.to !== 'string'))
  throw new Error('files must be an array of {from, to} strings');
await fetch('/document/move-files', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ files }) });

Type guard

function isMoveFilesPayload(p) {
  return typeof p === 'object' && p !== null && Array.isArray(p.files)
    && p.files.every((f) => typeof f?.from === 'string' && typeof f?.to === 'string');
}

Prevention

When it happens

Trigger: Calling /document/move-files with a body where files is null/undefined/not an array, or sending form-encoded instead of JSON so reqBody parsing yields an unexpected shape; a Prisma/DB failure while listing embedded files.

Common situations: Client sends {files: null} or omits the field; hand-rolled scripts posting the wrong content type; database briefly unreachable.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/2fe0cca09b9e8f96. Report an issue: GitHub.