{"record":{"id":"98d1c75d18115c4f","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-room-98d1c7","errorCode":"error-invalid-room","errorMessage":"Invalid room","messagePattern":"Invalid room","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/rooms/archiveRoom.ts","lineNumber":30,"sourceCode":"\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tarchiveRoom(rid: string): Promise<void>;\n\t}\n}\n\nexport const executeArchiveRoom = 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\tif (!room) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'archiveRoom' });\n\t}\n\n\tif (!(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE, userId))) {\n\t\tthrow new Meteor.Error('error-direct-message-room', `rooms type: ${room.t} can not be archived`, { method: 'archiveRoom' });\n\t}\n\n\tif (!(await hasPermissionAsync(userId, 'archive-room', room._id))) {\n\t\tthrow new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'archiveRoom' });\n\t}\n\n\treturn archiveRoom(rid, user);\n};\n\nMeteor.methods<ServerMethods>({\n\tasync archiveRoom(rid) {\n\t\tmethodDeprecationLogger.method('archiveRoom', '9.0.0', '/v1/channels.archive');\n\t\tconst userId = Meteor.userId();\n\t\tif (!userId) {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/archiveRoom.ts#L12-L48","documentation":"Thrown by executeArchiveRoom when Rooms.findOneById(rid) returns null: no room document matches the id passed to archiveRoom. The room record is required for the subsequent type-directive and permission checks, so a nonexistent room aborts immediately with error-invalid-room.","triggerScenarios":"Meteor.call('archiveRoom', rid) where rid was deleted after the client loaded it (stale UI/subscription); passing a subscription _id or team id where the room _id is expected; scripts using exported room lists that are out of date.","commonSituations":"Archiving from a stale tab after another admin removed the room; rid typos or truncation in automation scripts; race where deletion completes between the client's check and the server's lookup.","solutions":["Confirm the room exists immediately before the call (e.g. GET /api/v1/rooms.info or the live local rooms cache).","Refresh the client's room subscriptions so deleted rooms disappear from the UI.","In automations, treat error-invalid-room as already-removed and skip it."],"exampleFix":"// before\nMeteor.call('archiveRoom', rid);\n\n// after\nconst room = roomsCollection.findOne({ _id: rid }); // local, subscription-fed cache\nif (!room) {\n  removeRoomFromList(rid); // room vanished - sync UI instead of erroring\n} else {\n  Meteor.call('archiveRoom', rid);\n}","handlingStrategy":"validation","validationCode":"// client minimongo pre-check against the active rooms subscription\nconst room = roomsCollection.findOne({ _id: rid });\nif (!room) {\n  // rid no longer resolves - refresh subscriptions or drop the room from the UI\n}","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('archiveRoom', rid);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-room') {\n    // room already gone: sync local state and move on\n    removeRoomFromList(rid);\n    return;\n  }\n  throw e;\n}","preventionTips":["Read rids from live subscriptions, never from persisted state that can outlive the room.","Before bulk archiving, re-fetch the room list immediately before iterating.","Treat error-invalid-room in automations as a benign already-deleted outcome."],"tags":["rocket-chat","meteor","ddp","archive-room","room-id","not-found"],"backgroundTag":"room-not-found","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}