{"record":{"id":"2c08a2a101d49e7a","repo":"RocketChat/Rocket.Chat","slug":"error-code-invalid","errorCode":"error-code-invalid","errorMessage":"Invalid code","messagePattern":"Invalid code","errorType":"error_code","errorClass":"MeteorError","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/services/room/service.ts","lineNumber":215,"sourceCode":"\t\tif (\n\t\t\tFederationActions.shouldPerformFederationAction(room) &&\n\t\t\t!isUserNativeFederated(user) &&\n\t\t\t!(await FederationMatrix.canUserAccessFederation(user))\n\t\t) {\n\t\t\tthrow new MeteorError('error-not-authorized-federation', 'Not authorized to access federation', { method: 'joinRoom' });\n\t\t}\n\n\t\tif (isRoomWithJoinCode(room) && !(await Authorization.hasPermission(user._id, 'join-without-join-code'))) {\n\t\t\tif (!joinCode) {\n\t\t\t\tthrow new MeteorError('error-code-required', 'Code required', { method: 'joinRoom' });\n\t\t\t}\n\n\t\t\tconst isCorrectJoinCode = !!(await Rooms.findOneByJoinCodeAndId(joinCode, room._id, {\n\t\t\t\tprojection: { _id: 1 },\n\t\t\t}));\n\n\t\t\tif (!isCorrectJoinCode) {\n\t\t\t\tthrow new MeteorError('error-code-invalid', 'Invalid code', { method: 'joinRoom' });\n\t\t\t}\n\t\t}\n\n\t\treturn addUserToRoom(room._id, user);\n\t}\n\n\tasync beforeLeave(room: IRoom): Promise<void> {\n\t\tFederationActions.blockIfRoomFederatedButServiceNotReady(room);\n\t}\n\n\tasync beforeUserRemoved(room: IRoom): Promise<void> {\n\t\tFederationActions.blockIfRoomFederatedButServiceNotReady(room);\n\t}\n\n\tasync beforeNameChange(room: IRoom): Promise<void> {\n\t\tFederationActions.blockIfRoomFederatedButServiceNotReady(room);\n\t}\n","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/services/room/service.ts#L197-L233","documentation":"The join-code branch of join() validates the supplied code with Rooms.findOneByJoinCodeAndId(joinCode, room._id); if no room matches, the code is wrong for this room and join throws Meteor error-code-invalid ('Invalid code', method 'joinRoom').","triggerScenarios":"Submitting an incorrect or outdated join code for a join-code-protected room: typos, codes rotated by owners, or copy/paste artifacts (extra whitespace).","commonSituations":"Owners changed the code after it was shared; users pasting codes with trailing spaces; case mismatches.","solutions":["Trim/verify the input and re-check the code with the room owner, then re-submit exactly","Owners can reset the room's join code and re-share it","Grant join-without-join-code to trusted roles to avoid code handling entirely"],"exampleFix":"// before\nawait roomService.join({ room, user, joinCode: codeFromUser });\n\n// after\nconst joinCode = codeFromUser?.trim();\nif (!joinCode) throw new Error('error-code-required');\nawait roomService.join({ room, user, joinCode });","handlingStrategy":"try-catch","validationCode":"const joinCode = rawInput?.trim();\nif (!joinCode) throw new Error('error-code-required');\nconst matches = await Rooms.findOneByJoinCodeAndId(joinCode, room._id, { projections: { _id: 1 } });\nif (!matches) {\n  // wrong code: re-prompt instead of calling join() and failing\n  return rePromptForJoinCode(room);\n}","typeGuard":"const isValidJoinCode = async (joinCode: string, roomId: string): Promise<boolean> =>\n  Boolean(await Rooms.findOneByJoinCodeAndId(joinCode.trim(), roomId, { projections: { _id: 1 } }));","tryCatchPattern":"try {\n  await roomService.join({ room, user, joinCode });\n} catch (err) {\n  if (err?.error === 'error-code-invalid') {\n    // re-prompt with a fresh attempt limit; do not auto-retry the same code\n    return rePromptForJoinCode(room);\n  }\n  throw err;\n}","preventionTips":["Trim join-code input before submitting","Ask owners to re-share the code after rotations instead of brute-forcing retries","Reset the room's join code when it is suspected compromised rather than chasing mismatches"],"tags":["rooms","join","join-code","rocket-chat"],"backgroundTag":"invalid-join-code","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}