{"record":{"id":"b0f58799f5c1978a","repo":"hcengineering/platform","slug":"invalid-workspace-user-workspace","errorCode":null,"errorMessage":"Invalid workspace: '${user.workspace}'","messagePattern":"Invalid workspace: '(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"services/telegram/pod-telegram/src/platform.ts","lineNumber":64,"sourceCode":"\n    await wsWorker.addUser(tgUser)\n  }\n\n  async getTarget ({ workspace, email }: User): Promise<[UserRecord, WorkspaceWorker | undefined]> {\n    const res = await this.storage.findOne({ email, workspace })\n\n    if (res === null) {\n      throw Error('User is not signed in')\n    }\n\n    return [res, this.clientMap.get(workspace)]\n  }\n\n  async removeUser (user: User): Promise<void> {\n    const [res, wsWorker] = await this.getTarget(user)\n\n    if (wsWorker === undefined) {\n      throw Error(`Invalid workspace: '${user.workspace}'`)\n    }\n\n    await wsWorker.removeUser({ phone: res.phone })\n  }\n\n  async getUserRecord ({ workspace, phone }: Pick<TgUser, 'workspace' | 'phone'>): Promise<UserRecord | undefined> {\n    return (await this.storage.findOne({ phone, workspace })) ?? undefined\n  }\n\n  static async createStorages (): Promise<\n  [Collection<UserRecord>, Collection<LastMsgRecord>, Collection<WorkspaceChannel>]\n  > {\n    const db = await getDB()\n    const userStorage = db.collection<UserRecord>('integrations')\n    const lastMsgStorage = db.collection<LastMsgRecord>('last-msgs')\n    const channelStorage = db.collection<WorkspaceChannel>('channels')\n\n    await userStorage.createIndex({ phone: 1, workspace: 1 }, { unique: true })","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/telegram/pod-telegram/src/platform.ts#L46-L82","documentation":"thrown by removeUser when getTarget() fails to resolve a worker for the user's workspace, meaning the workspace name on the User record does not match any registered workspace worker. It guards against calling removeUser on a worker that does not exist.","triggerScenarios":"removeUser(user) is called with a User whose user.workspace string is not a known/registered workspace (typo, deleted workspace, or user record from a different environment).","commonSituations":"Workspaces renamed or removed while user records still reference the old name; cross-environment data (staging user in production); typo in workspace identifier.","solutions":["Verify user.workspace matches an existing registered workspace before calling removeUser","Look up the workspace list and correct or migrate the user record's workspace field","If the workspace was intentionally deleted, clean up or reassign the stale user records","Add a pre-check that resolves the workspace and returns a friendly error to the caller"],"exampleFix":"// before\nawait pod.removeUser(user) // throws if workspace unknown\n// after\nconst ws = workspaces.find(w => w.name === user.workspace)\nif (ws === undefined) throw new Error(`Unknown workspace: ${user.workspace}`)\nawait pod.removeUser(user)","handlingStrategy":"validation","validationCode":"const known = new Set(workspaces.map(w => w.name))\nif (!known.has(user.workspace)) throw new Error(`Unknown workspace: ${user.workspace}`)","typeGuard":"function hasWorkspace<T extends { workspace: string }>(user: T, known: Set<string>): boolean {\n  return known.has(user.workspace)\n}","tryCatchPattern":"try {\n  await pod.removeUser(user)\n} catch (err) {\n  if (err.message.startsWith('Invalid workspace:')) {\n    console.warn(`Skipping user in unknown workspace ${user.workspace}`)\n    return\n  }\n  throw err\n}","preventionTips":["Keep user.workspace values in sync with the registered workspace registry","Validate workspace references when creating user records","Clean up user records when a workspace is deleted"],"tags":["telegram","workspace","state"],"backgroundTag":"unknown-workspace-reference","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}