{"record":{"id":"3ac44ca858aa1b15","repo":"RocketChat/Rocket.Chat","slug":"failed-to-load-file-contents","errorCode":null,"errorMessage":"Failed to load file contents.","messagePattern":"Failed to load file contents\\.","errorType":"exception","errorClass":"Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/lib/import/omnichannel-contacts/ContactImporter.ts","lineNumber":32,"sourceCode":"\n\tconstructor(info: ImporterInfo, importRecord: IImport, converterOptions: ConverterOptions = {}) {\n\t\tsuper(info, importRecord, converterOptions);\n\n\t\tthis.csvParser = parse;\n\t}\n\n\toverride async prepareUsingLocalFile(fullFilePath: string): Promise<ImporterProgress> {\n\t\tthis.logger.debug('start preparing import operation');\n\t\tawait this.converter.clearImportData();\n\n\t\tImporterWebsocket.progressUpdated({ rate: 0 });\n\n\t\tawait super.updateProgress(ProgressStep.PREPARING_CONTACTS);\n\t\t// Reading the whole file at once for compatibility with the code written for the other importers\n\t\t// We can change this to a stream once we improve the rest of the importer classes\n\t\tconst fileContents = fs.readFileSync(fullFilePath, { encoding: 'utf8' });\n\t\tif (!fileContents || typeof fileContents !== 'string') {\n\t\t\tthrow new Error('Failed to load file contents.');\n\t\t}\n\n\t\tconst parsedContacts = this.csvParser(fileContents);\n\t\tconst contactsCount = await addParsedContacts.call(this.converter, parsedContacts);\n\n\t\tif (contactsCount === 0) {\n\t\t\tthis.logger.error('No contacts found in the import file.');\n\t\t\tawait super.updateProgress(ProgressStep.ERROR);\n\t\t} else {\n\t\t\tawait super.updateRecord({ 'count.contacts': contactsCount, 'count.total': contactsCount });\n\t\t\tImporterWebsocket.progressUpdated({ rate: 100 });\n\t\t}\n\n\t\treturn super.getProgress();\n\t}\n}\n","sourceCodeStart":14,"sourceCodeEnd":49,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/import/omnichannel-contacts/ContactImporter.ts#L14-L49","documentation":"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.","triggerScenarios":"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.","commonSituations":"User uploads an empty or truncated export; upload chunking failed silently leaving a 0-byte temp file; file cleanup raced the import start.","solutions":["Re-export the CSV at the source and confirm it is non-empty UTF-8 text","Verify the uploaded file's size is > 0 before starting the import","Retry the import with the corrected file"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const stat = await fs.promises.stat(fullFilePath);\nif (!stat.isFile() || stat.size === 0) {\n  // reject the upload before starting the import\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate uploaded file size and encoding at upload time, not during import","Reject zero-byte uploads in the UI with a clear message","Ensure upload completion is confirmed before the import job starts"],"tags":["import","omnichannel","contacts","csv","file-io"],"backgroundTag":"file-read-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}