{"record":{"id":"67d7ef94e8607842","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-67d7ef","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/rooms/unarchiveRoom.ts","lineNumber":23,"sourceCode":"import { Meteor } from 'meteor/meteor';\n\nimport { hasPermissionAsync } from '../../lib/authorization/hasPermission';\nimport { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\nimport { unarchiveRoom } from '../../lib/rooms/unarchiveRoom';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tunarchiveRoom(rid: string): Promise<void>;\n\t}\n}\n\nexport const executeUnarchiveRoom = async (userId: string, rid: string) => {\n\tcheck(rid, String);\n\n\tconst user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });\n\tif (!user || !isRegisterUser(user)) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });\n\t}\n\n\tconst room = await Rooms.findOneById(rid);\n\n\tif (!room) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'unarchiveRoom' });\n\t}\n\n\tif (!(await hasPermissionAsync(userId, 'unarchive-room', room._id))) {\n\t\tthrow new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'unarchiveRoom' });\n\t}\n\n\treturn unarchiveRoom(rid, user);\n};\n\nMeteor.methods<ServerMethods>({\n\tasync unarchiveRoom(rid) {\n\t\tmethodDeprecationLogger.method('unarchiveRoom', '9.0.0', '/v1/channels.unarchive');","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/unarchiveRoom.ts#L5-L41","documentation":"executeUnarchiveRoom loads the user and requires isRegisterUser — a guard from @rocket.chat/core-typings that demands both username and name be defined on the user document. The call throws error-invalid-user when the record is missing or lacks those fields. Note the error detail names method 'archiveRoom': a copy-paste artifact from the sibling method; the failing call is unarchiveRoom.","triggerScenarios":"Unarchiving with a userId whose Users document was deleted, or whose document has no username or no name (incomplete provisioning, some bot/app accounts); server-side invocation with a fabricated id.","commonSituations":"Bot or app accounts without a populated name field used for moderation actions; users mid-provisioning; partial user records created by a faulty import.","solutions":["Run unarchiveRoom as a fully provisioned user whose record has both username and name","Fix the user document (set the missing name) or switch to a proper admin account","Validate the acting user server-side (findOneById + isRegisterUser) before invoking executeUnarchiveRoom","Do not route on the misleading 'archiveRoom' string in the error details"],"exampleFix":"// before\nawait executeUnarchiveRoom(botUserId, rid); // bot user has no `name` field\n\n// after\nconst user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });\nif (!user || !isRegisterUser(user)) throw new Meteor.Error('error-invalid-user', 'Invalid user');\nawait executeUnarchiveRoom(user._id, rid);","handlingStrategy":"validation","validationCode":"import { isRegisterUser } from '@rocket.chat/core-typings';\n\nconst user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });\nif (!user || !isRegisterUser(user)) {\n  // pick a fully provisioned user (username AND name set) before calling unarchiveRoom\n}","typeGuard":"// server-side, after the projection load\nconst isValidActor = (u: { username?: string; name?: string } | null): u is { username: string; name: string } =>\n  !!u && u.username !== undefined && u.name !== undefined;","tryCatchPattern":"try {\n  await Meteor.callAsync('unarchiveRoom', rid);\n} catch (error) {\n  if (error instanceof Meteor.Error && error.error === 'error-invalid-user') {\n    // acting user missing or incomplete (no username/name): switch to a real admin account\n  }\n}","preventionTips":["Run moderation actions as fully provisioned users (username and name populated)","Do not use bare bot/app accounts for archive flows without verifying their profile","Ignore the 'archiveRoom' string in this error's details — it is a copy-paste artifact"],"tags":["users","validation","meteor-methods"],"backgroundTag":"user-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}