{"record":{"id":"88341f03004b3632","repo":"RocketChat/Rocket.Chat","slug":"the-file-contains-invalid-syntax","errorCode":null,"errorMessage":"The file contains invalid syntax","messagePattern":"The file contains invalid syntax","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/lib/import/csv/CsvImporter.ts","lineNumber":171,"sourceCode":"\t\t\t\tincreaseProgressCount();\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Parse the messages\n\t\t\tif (entry.entryName.indexOf('/') > -1) {\n\t\t\t\tif (this.progress.step !== ProgressStep.PREPARING_MESSAGES) {\n\t\t\t\t\tawait super.updateProgress(ProgressStep.PREPARING_MESSAGES);\n\t\t\t\t}\n\n\t\t\t\tconst item = entry.entryName.split('/'); // random/messages.csv\n\t\t\t\tconst folderName = item[0]; // random\n\n\t\t\t\tlet msgs = [];\n\n\t\t\t\ttry {\n\t\t\t\t\tmsgs = this.csvParser(entry.getData().toString());\n\t\t\t\t} catch (e) {\n\t\t\t\t\tthis.logger.warn({ msg: 'The file contains invalid syntax', entryName: entry.entryName, err: e });\n\t\t\t\t\tincreaseProgressCount();\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlet data: { username: string; ts: string; text: string; otherUsername?: string; isDirect?: true }[];\n\t\t\t\tconst msgGroupData = item[1].split('.')[0]; // messages\n\t\t\t\tlet isDirect = false;\n\n\t\t\t\tif (folderName.toLowerCase() === 'directmessages') {\n\t\t\t\t\tisDirect = true;\n\t\t\t\t\tdata = msgs.map((m) => ({\n\t\t\t\t\t\tusername: m[0],\n\t\t\t\t\t\tts: m[2],\n\t\t\t\t\t\ttext: m[3],\n\t\t\t\t\t\totherUsername: m[1],\n\t\t\t\t\t\tisDirect: true,\n\t\t\t\t\t}));\n\t\t\t\t} else {","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/import/csv/CsvImporter.ts#L153-L189","documentation":"The CSV importer parses each messages.csv entry from the uploaded zip; the CSV parser threw on this file, meaning its syntax does not match the expected dialect. The file is skipped — its messages are lost from the import — while the progress counter still advances so the import completes.","triggerScenarios":"Delimiter mismatch (file uses ';' but the parser expects ','), unbalanced/missing quotes around fields containing commas, stray newlines inside unquoted message text, files saved by Excel with BOM/UTF-16 encoding, or a non-CSV file placed at the expected path inside the zip.","commonSituations":"Hand-edited CSV exports; Excel 'Save as CSV' with regional settings producing different delimiters or encodings; zips built with wrong folder layout on Windows; message text containing raw line breaks.","solutions":["Open the failing entryName from the log and validate it: plain UTF-8, comma-delimited, every field properly quoted","Re-export ensuring each row is username,timestamp,text with quotes around any field containing commas or newlines","Re-zip with the expected folder structure and re-run the import"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// validate the CSV before feeding the parser\nimport { parse } from 'csv-parse/sync';\n\nfunction parseMessagesCsv(raw: string): unknown[] {\n\treturn parse(raw, { delimiter: ',', relax_quotes: false, skip_empty_lines: true, bom: true });\n}","typeGuard":null,"tryCatchPattern":"try {\n\tmsgs = this.csvParser(entry.getData().toString());\n} catch (e) {\n\tthis.logger.warn({ msg: 'The file contains invalid syntax', entryName: entry.entryName, err: e });\n\tincreaseProgressCount();\n\tcontinue; // skip file, keep the import going\n}","preventionTips":["Validate every messages.csv with a CSV linter before zipping the import file","Export with UTF-8, comma delimiter, and quoted fields containing commas/newlines","Keep the expected folder structure inside the zip unchanged"],"tags":["import","csv","importer","data-validation"],"backgroundTag":"csv-parse-error","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"}