{"record":{"id":"b7d5fd768387d855","repo":"RocketChat/Rocket.Chat","slug":"subscription-not-found","errorCode":null,"errorMessage":"Subscription not found","messagePattern":"Subscription not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"apps/meteor/client/lib/chats/data.ts","lineNumber":301,"sourceCode":"\tconst getDiscussionByID = async (drid: IRoom['_id']): Promise<IRoom> => {\n\t\tconst discussion = await findDiscussionByID(drid);\n\n\t\tif (!discussion) {\n\t\t\tthrow new Error('Discussion not found');\n\t\t}\n\n\t\treturn discussion;\n\t};\n\n\tconst createStrictGetter = <TFind extends (...args: any[]) => Promise<any>>(\n\t\tfind: TFind,\n\t\terrorMessage: string,\n\t): ((...args: Parameters<TFind>) => Promise<Exclude<Awaited<ReturnType<TFind>>, undefined>>) => {\n\t\treturn async (...args) => {\n\t\t\tconst result = await find(...args);\n\n\t\t\tif (!result) {\n\t\t\t\tthrow new Error(errorMessage);\n\t\t\t}\n\n\t\t\treturn result;\n\t\t};\n\t};\n\n\tconst findSubscription = async (): Promise<ISubscription | undefined> => {\n\t\treturn Subscriptions.state.find((record) => record.rid === rid);\n\t};\n\n\tconst getSubscription = createStrictGetter(findSubscription, 'Subscription not found');\n\n\tconst findSubscriptionFromMessage = async (message: IMessage): Promise<ISubscription | undefined> => {\n\t\treturn Subscriptions.state.find((record) => record.rid === message.rid);\n\t};\n\n\tconst getSubscriptionFromMessage = createStrictGetter(findSubscriptionFromMessage, 'Subscription not found');\n","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/2f18297792c973da326be7253f497d239ea6f2b0/apps/meteor/client/lib/chats/data.ts#L283-L319","documentation":"getSubscription is produced by createStrictGetter(findSubscription, 'Subscription not found'): it throws when Subscriptions.state.find finds no record with rid matching the chat context. A missing subscription means the current user is not (or not yet) a member of the room in the client's synced state.","triggerScenarios":"Calling getSubscription while previewing a public channel the user has not joined, before subscriptions finish syncing after login, after being removed from the room while its UI is still open, or for a logged-out/anonymized state.","commonSituations":"Public channel preview flows, notification deep-links into unjoined rooms, team channels the user was kicked from mid-session, race at app startup.","solutions":["Check isSubscribedToRoom() first and branch (join prompt vs member UI).","Use the underlying findSubscription and handle undefined.","Ensure the subscriptions store is loaded before rendering member-only affordances."],"exampleFix":"// before\nconst sub = await chat.getSubscription();\n\n// after\nif (!(await chat.isSubscribedToRoom())) {\n  // not a member: preview UI or joinRoom() first\n  return;\n}\nconst sub = await chat.getSubscription();","handlingStrategy":"validation","validationCode":"if (!(await chat.isSubscribedToRoom())) {\n  // previewing without membership — join first or render preview UI\n  return;\n}\nconst sub = await chat.getSubscription();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Branch UI on isSubscribedToRoom() before touching subscriptions.","Remember public-channel previews have rooms but no subscription records.","Re-check membership after join/leave transitions update the store."],"tags":["subscriptions","rooms","cache"],"backgroundTag":"subscription-not-found","analyzedSha":"2f18297792c973da326be7253f497d239ea6f2b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}