{"record":{"id":"5913a1a6855bc134","repo":"RocketChat/Rocket.Chat","slug":"cannot-reset-room-key","errorCode":null,"errorMessage":"Cannot reset room key","messagePattern":"Cannot reset room key","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/client/views/room/hooks/useE2EEResetRoomKey.ts","lineNumber":21,"sourceCode":"import type { UseMutationOptions, UseMutationResult } from '@tanstack/react-query';\nimport { useMutation } from '@tanstack/react-query';\n\nimport { e2e } from '../../../lib/e2ee';\n\ntype UseE2EEResetRoomKeyVariables = {\n\troomId: IRoom['_id'];\n};\n\nexport const useE2EEResetRoomKey = (\n\toptions?: Omit<UseMutationOptions<void, Error, UseE2EEResetRoomKeyVariables>, 'mutationFn'>,\n): UseMutationResult<void, Error, UseE2EEResetRoomKeyVariables> => {\n\tconst resetRoomKey = useEndpoint('POST', '/v1/e2e.resetRoomKey');\n\n\treturn useMutation({\n\t\tmutationFn: async ({ roomId }) => {\n\t\t\tconst e2eRoom = await e2e.getInstanceByRoomId(roomId);\n\t\t\tif (!e2eRoom) {\n\t\t\t\tthrow new Error('Cannot reset room key');\n\t\t\t}\n\n\t\t\tconst { e2eKey, e2eKeyId } = (await e2eRoom.resetRoomKey()) ?? {};\n\n\t\t\tif (!e2eKey || !e2eKeyId) {\n\t\t\t\tthrow new Error('Cannot reset room key');\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait resetRoomKey({ rid: roomId, e2eKeyId, e2eKey });\n\t\t\t} catch (error) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\n\t\t...options,\n\t});\n};","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/client/views/room/hooks/useE2EEResetRoomKey.ts#L3-L39","documentation":"Thrown by the useE2EEResetRoomKey mutation at two distinct points: (1) when e2e.getInstanceByRoomId(roomId) returns no E2E room instance (the room is not encrypted or the E2E client has not initialized an instance for it), and (2) when e2eRoom.resetRoomKey() returns no e2eKey or e2eKeyId (the key reset operation failed to produce a new key pair). The mutation posts the new key to /v1/e2e.resetRoomKey.","triggerScenarios":"The room is not E2E encrypted (no e2e instance exists for it). The E2E client has not finished initializing for this room (startClient not called or still pending). resetRoomKey() internally fails (key generation error, keychain access failure). The E2E keychain is locked or unavailable. Secure context requirements not met (see error 106).","commonSituations":"User tries to reset E2E key for a room that is not encrypted. E2E client is in a transitional state (not READY). Browser's crypto/keychain APIs unavailable (insecure context). Corrupted key material preventing reset. E2E setup incomplete (user hasn't set up their E2E password).","solutions":["Verify the room is E2E encrypted before showing the reset-key option.","Ensure the E2E client is in READY state (check e2e.state) before calling the mutation.","Catch the mutation error in the UI and show a descriptive message ('E2E not active for this room' vs 'key reset failed').","If resetRoomKey returned no key, retry after confirming secure context and keychain availability."],"exampleFix":"// before\nconst reset = useE2EEResetRoomKey();\nreset.mutate({ roomId }); // no guard\n// after\nconst reset = useE2EEResetRoomKey({\n  onError: (error) => {\n    if (error.message === 'Cannot reset room key') {\n      dispatchToastMessage({ type: 'error', message: t('E2E_not_available_for_room') });\n    }\n  },\n});\n// only call when room is encrypted:\nif (room.encrypted) {\n  reset.mutate({ roomId });\n}","handlingStrategy":"validation","validationCode":"const e2eRoom = await e2e.getInstanceByRoomId(roomId);\nif (!e2eRoom) {\n  // room is not encrypted or E2E not initialized\n  dispatchToastMessage({ type: 'error', message: t('E2E_not_active') });\n  return;\n}\n// proceed with key reset","typeGuard":"const isRoomE2EEncrypted = async (roomId: string): Promise<boolean> => {\n  return Boolean(await e2e.getInstanceByRoomId(roomId));\n};","tryCatchPattern":"const reset = useE2EEResetRoomKey({\n  onError: (error) => {\n    if (error.message === 'Cannot reset room key') {\n      dispatchToastMessage({ type: 'error', message: t('E2E_key_reset_failed') });\n    }\n  },\n});","preventionTips":["Verify the room is E2E encrypted (getInstanceByRoomId returns a value) before showing the reset-key action.","Ensure the E2E client is in READY state before initiating key operations.","Use the mutation's onError callback for user-facing error handling.","Confirm secure context (HTTPS) and keychain availability before E2E operations."],"tags":["e2ee","encryption","room-key","mutation","react-query","security"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}