Mintplex-Labs/anything-llm · error
Filename is required!
Error message
Filename is required!
What it means
Thrown by `writeToServerDocuments` when `filename` is falsy. This function writes parsed document JSON to the server's documents directory, so a missing filename means it cannot construct a destination file path — it fails fast rather than writing to an arbitrary or empty name. The check is a required-argument guard, not a runtime/environment condition.
Source
Thrown at collector/utils/files/index.js:126
}
/**
* Writes a document to the server documents folder.
* @param {Object} params - The parameters for the function.
* @param {Object} params.data - The data to write to the file. Must look like a document object.
* @param {string} params.filename - The name of the file to write to.
* @param {string|null} params.destinationOverride - A forced destination to write to - will be honored if provided.
* @param {Object} params.options - The options for the function.
* @param {boolean} params.options.parseOnly - If true, the file will be written to the direct uploads folder instead of the documents folder. Will be ignored if destinationOverride is provided.
* @returns {Object} - The data with the location added.
*/
function writeToServerDocuments({
data = {},
filename,
destinationOverride = null,
options = {},
}) {
if (!filename) throw new Error("Filename is required!");
let destination = null;
if (destinationOverride) destination = path.resolve(destinationOverride);
else if (options.parseOnly) destination = path.resolve(directUploadsFolder);
else destination = path.resolve(documentsFolder, "custom-documents");
if (!fs.existsSync(destination))
fs.mkdirSync(destination, { recursive: true });
const safeFilename = sanitizeFileName(filename);
const destinationFilePath = normalizePath(
path.resolve(destination, safeFilename) + ".json"
);
fs.writeFileSync(destinationFilePath, JSON.stringify(data, null, 4), {
encoding: "utf-8",
});
return {View on GitHub (pinned to 526360e320)
Solutions
- Ensure every caller computes a non-empty filename (use the source file name, a UUID, or a slugified title).
- Add a fallback such as `filename = filename || document-${Date.now()}` before the call.
- Validate the filename upstream with a type check and reject ingestion jobs missing it.
- Unit-test parsers to assert they always emit a filename.
Example fix
// before
await writeToServerDocuments({ data, filename: record.title });
// after
const filename = record.title || record.name || `doc-${path.basename(sourcePath) || uuidv4()}`;
if (!filename) throw new Error('Cannot determine filename for document');
await writeToServerDocuments({ data, filename }); Defensive patterns
Strategy: validation
Validate before calling
function withFilename(data, candidate) {
const filename = candidate || data.title || data.name || `doc-${Date.now()}`;
if (!filename) throw new Error('Cannot determine filename for document');
return { data, filename };
} Type guard
function hasNonEmptyFilename(arg) {
return typeof arg?.filename === 'string' && arg.filename.trim().length > 0;
} Try / catch
try {
await writeToServerDocuments({ data, filename });
} catch (e) {
if (/Filename is required/i.test(e.message)) {
filename = `doc-${Date.now()}`;
await writeToServerDocuments({ data, filename });
} else throw e;
} Prevention
- Always compute a filename from the source (file name, slugified title, or UUID) before calling.
- Add a unit test asserting parsers always emit a filename.
- Reject ingestion jobs without a name upstream.
When it happens
Trigger: Calling `writeToServerDocuments({ data })` with no filename; passing `filename: null`/`''`/`undefined`; a parser that produces documents without setting a name field; destructuring a record whose `title`/`name` key is absent and feeding it as filename.
Common situations: A new connector/parser forgets to set the filename; a PDF/URL ingest where the source has no extractable title; refactoring renames the field but misses this call site.
Related errors
- Invalid path.
- Input file ${inputPath} does not exist.
- Invalid video id!
- Impossible to retrieve Youtube video ID.
- Invalid path name
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/fb90d934d6b9509a.
Report an issue: GitHub.