{"record":{"id":"28541c73a24ab190","repo":"RocketChat/Rocket.Chat","slug":"importer-message-unknown-user","errorCode":null,"errorMessage":"importer-message-unknown-user","messagePattern":"importer-message-unknown-user","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/import/classes/converters/MessageConverter.ts","lineNumber":59,"sourceCode":"\tprotected async resetLastMessages(): Promise<void> {\n\t\tfor (const rid of this.rids) {\n\t\t\ttry {\n\t\t\t\tawait Rooms.resetLastMessageById(rid, null);\n\t\t\t} catch (err) {\n\t\t\t\tthis._logger.error({ msg: 'Failed to update last message of room', roomId: rid, err });\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected async insertMessage(data: IImportMessage): Promise<void> {\n\t\tif (!data.ts || isNaN(data.ts as unknown as number)) {\n\t\t\tthrow new Error('importer-message-invalid-timestamp');\n\t\t}\n\n\t\tconst creator = await this._cache.findImportedUser(data.u._id);\n\t\tif (!creator) {\n\t\t\tthis._logger.warn({ msg: 'Imported user not found', userId: data.u._id });\n\t\t\tthrow new Error('importer-message-unknown-user');\n\t\t}\n\t\tconst rid = await this._cache.findImportedRoomId(data.rid);\n\t\tif (!rid) {\n\t\t\tthrow new Error('importer-message-unknown-room');\n\t\t}\n\t\tif (!this.rids.includes(rid)) {\n\t\t\tthis.rids.push(rid);\n\t\t}\n\n\t\tconst msgObj = await this.buildMessageObject(data, rid, creator);\n\n\t\ttry {\n\t\t\tawait insertMessage(creator, msgObj as unknown as IDBMessage, rid, true);\n\t\t} catch (err) {\n\t\t\tthis._logger.error({ msg: 'Failed to import message', timestamp: msgObj.ts, roomId: rid, err });\n\t\t}\n\t}\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/import/classes/converters/MessageConverter.ts#L41-L77","documentation":"Thrown while an importer (Slack, HipChat, CSV, etc.) inserts messages: the message's creator (data.u._id) could not be resolved by ConverterCache.findImportedUser to a previously imported Rocket.Chat user. The error aborts that record; the import framework counts it as a failed message and continues with the rest.","triggerScenarios":"A source export whose messages reference users absent from the users data (deleted/left accounts not in users.json); a partial import where the users stage failed earlier; custom importers that add messages before users are converted so the cache is cold.","commonSituations":"Slack workspaces with deleted accounts; export files trimmed by hand; import runs where user-stage errors were ignored until messages started referencing the missing users.","solutions":["Check the import log's earlier user-stage errors - missing users almost always originate there","Re-export from the source including all users, so every message author is covered","Pre-scan the export: collect message author ids and diff them against the user ids; add missing users or remap them to a placeholder account","For custom importers, fully convert users before the message pass so ConverterCache can resolve ids"],"exampleFix":"// pre-flight check before running the import\nconst importedUsers = new Set(users.map((u) => u._id));\nconst missingAuthors = [...new Set(messages.map((m) => m.u?._id).filter(Boolean))].filter((id) => !importedUsers.has(id));\nif (missingAuthors.length) {\n  console.warn('Messages reference unknown users:', missingAuthors);\n  // add them to the import data or remap to a placeholder user before importing\n}","handlingStrategy":"validation","validationCode":"const importedUserIds = new Set(users.map((u) => u._id));\nconst missingAuthors = [...new Set(messages.map((m) => m.u?._id).filter(Boolean))].filter((id) => !importedUserIds.has(id));\nif (missingAuthors.length) {\n  // add the missing users or remap them to a placeholder before importing messages\n}","typeGuard":null,"tryCatchPattern":"try {\n  await converter.addMessage(message, useUpsert);\n} catch (error) {\n  if ((error as Error).message === 'importer-message-unknown-user') {\n    logger.warn({ msg: 'skip message with unknown author', messageId: message._id });\n    return; // keep importing the remaining messages\n  }\n  throw error;\n}","preventionTips":["Always import/convert users before messages so ConverterCache can resolve ids","Pre-validate referential integrity of exports (authors, rooms) before starting","Keep a placeholder user for deleted accounts from the source platform"],"tags":["importer","messages","user-mapping","data-integrity"],"backgroundTag":"import-missing-user-reference","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}