{"record":{"id":"f9a061a052098163","repo":"RocketChat/Rocket.Chat","slug":"invalid-list-of-rooms","errorCode":null,"errorMessage":"invalid-list-of-rooms","messagePattern":"invalid-list-of-rooms","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/services/team/service.ts","lineNumber":639,"sourceCode":"\t\t}\n\n\t\treturn {\n\t\t\ttotal,\n\t\t\trecords,\n\t\t};\n\t}\n\n\tasync getMatchingTeamRooms(teamId: string, rids: Array<string>): Promise<Array<string>> {\n\t\tif (!teamId) {\n\t\t\tthrow new Error('missing-teamId');\n\t\t}\n\n\t\tif (!rids) {\n\t\t\treturn [];\n\t\t}\n\n\t\tif (!Array.isArray(rids)) {\n\t\t\tthrow new Error('invalid-list-of-rooms');\n\t\t}\n\n\t\tconst rooms = await Rooms.findByTeamIdAndRoomsId(teamId, rids, {\n\t\t\tprojection: { _id: 1 },\n\t\t}).toArray();\n\t\treturn rooms.map(({ _id }: { _id: string }) => _id);\n\t}\n\n\tasync getMembersByTeamIds(teamIds: Array<string>, options: FindOptions<ITeamMember>): Promise<Array<ITeamMember>> {\n\t\treturn TeamMember.findByTeamIds(teamIds, options).toArray();\n\t}\n\n\tasync members(\n\t\tuid: string,\n\t\tteamId: string,\n\t\tcanSeeAll: boolean,\n\t\t{ offset, count }: IPaginationOptions = { offset: 0, count: 50 },\n\t\tquery: Filter<IUser> = {},","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/services/team/service.ts#L621-L657","documentation":"Thrown by TeamService.getMatchingTeamRooms (apps/meteor/server/services/team/service.ts:639) when `rids` is truthy but not an array (e.g. a string, number, or plain object). Note the asymmetry: null/undefined rids returns [] silently — only a truthy non-array throws. The declared type is Array<string>, so this is a runtime type guard against unvalidated input from JavaScript callers or deserialized payloads.","triggerScenarios":"Calling getMatchingTeamRooms(teamId, 'room1,room2') with a comma-joined string instead of ['room1','room2']; passing an object map of rooms; a JSON payload where rooms arrives as a single string because the sender serialized one element without an array. REST schemas enforce array types upstream, so this bites direct callers.","commonSituations":"Apps Engine integrations receiving loosely-typed payloads; REST clients sending rooms: 'abc' instead of rooms: ['abc']; code doing rooms.toString() or joining IDs for logging and accidentally forwarding the string.","solutions":["Pass a genuine array of room ID strings: Team.getMatchingTeamRooms(teamId, ['room1', 'room2'])","Normalize input first: const list = Array.isArray(rids) ? rids : typeof rids === 'string' ? rids.split(',').filter(Boolean) : []","Pass null/undefined instead of an empty non-array if you mean 'no rooms' — null short-circuits to []"],"exampleFix":"// before\nawait Team.getMatchingTeamRooms(teamId, 'room1,room2'); // string → throws invalid-list-of-rooms\n\n// after\nconst rids: string[] = Array.isArray(input) ? input : String(input).split(',').filter(Boolean);\nawait Team.getMatchingTeamRooms(teamId, rids);","handlingStrategy":"type-guard","validationCode":"const rooms: string[] = Array.isArray(rids) ? rids.filter((r): r is string => typeof r === 'string' && r.length > 0) : [];","typeGuard":"const isRoomIdList = (v: unknown): v is string[] =>\n\tArray.isArray(v) && v.every((item) => typeof item === 'string');","tryCatchPattern":"try {\n\tawait Team.getMatchingTeamRooms(teamId, rooms);\n} catch (e) {\n\tif (e instanceof Error && e.message === 'invalid-list-of-rooms') {\n\t\t// payload shape wrong — normalize to string[] and retry once\n\t}\n\tthrow e;\n}","preventionTips":["Always send rooms as a JSON array of ID strings, even for a single room","Remember null/undefined returns [] silently — only truthy non-arrays throw","Validate external payloads with Array.isArray before crossing into service calls"],"tags":["rocket-chat","teams","type-validation","rooms","server-side"],"backgroundTag":"type-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}