RocketChat/Rocket.Chat · error · Error

Failed to load file contents.

Error message

Failed to load file contents.

What it means

The omnichannel contact importer reads the whole uploaded file with fs.readFileSync(fullFilePath, 'utf8') during prepareUsingLocalFile and throws when the result is falsy — practically, when the file is empty (0 bytes), since a utf8 read always yields a string. Import preparation aborts before CSV parsing.

Source

Thrown at apps/meteor/server/lib/import/omnichannel-contacts/ContactImporter.ts:32

	constructor(info: ImporterInfo, importRecord: IImport, converterOptions: ConverterOptions = {}) {
		super(info, importRecord, converterOptions);

		this.csvParser = parse;
	}

	override async prepareUsingLocalFile(fullFilePath: string): Promise<ImporterProgress> {
		this.logger.debug('start preparing import operation');
		await this.converter.clearImportData();

		ImporterWebsocket.progressUpdated({ rate: 0 });

		await super.updateProgress(ProgressStep.PREPARING_CONTACTS);
		// Reading the whole file at once for compatibility with the code written for the other importers
		// We can change this to a stream once we improve the rest of the importer classes
		const fileContents = fs.readFileSync(fullFilePath, { encoding: 'utf8' });
		if (!fileContents || typeof fileContents !== 'string') {
			throw new Error('Failed to load file contents.');
		}

		const parsedContacts = this.csvParser(fileContents);
		const contactsCount = await addParsedContacts.call(this.converter, parsedContacts);

		if (contactsCount === 0) {
			this.logger.error('No contacts found in the import file.');
			await super.updateProgress(ProgressStep.ERROR);
		} else {
			await super.updateRecord({ 'count.contacts': contactsCount, 'count.total': contactsCount });
			ImporterWebsocket.progressUpdated({ rate: 100 });
		}

		return super.getProgress();
	}
}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Re-export the CSV at the source and confirm it is non-empty UTF-8 text
  2. Verify the uploaded file's size is > 0 before starting the import
  3. Retry the import with the corrected file
Defensive patterns

Strategy: validation

Validate before calling

const stat = await fs.promises.stat(fullFilePath);
if (!stat.isFile() || stat.size === 0) {
  // reject the upload before starting the import
}

Prevention

When it happens

Trigger: prepareUsingLocalFile runs on an upload that produced an empty temp file: zero-byte CSV, an interrupted upload, or a wrong path that still resolved to an empty file.

Common situations: User uploads an empty or truncated export; upload chunking failed silently leaving a 0-byte temp file; file cleanup raced the import start.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/3ac44ca858aa1b15. Report an issue: GitHub.