{"record":{"id":"ac52c1a69b1d83e2","repo":"hcengineering/platform","slug":"socialidnotfound-ac52c1","errorCode":"SocialIdNotFound","errorMessage":"SocialIdNotFound","messagePattern":"SocialIdNotFound","errorType":"exception","errorClass":"PlatformError","httpStatus":null,"severity":"error","filePath":"server/account/src/serviceOperations.ts","lineNumber":651,"sourceCode":"export async function updateSocialId (\n  ctx: MeasureContext,\n  db: AccountDB,\n  branding: Branding | null,\n  token: string,\n  params: { personId: PersonId, displayValue: string }\n): Promise<void> {\n  const { personId, displayValue } = params\n  const { extra } = decodeTokenVerbose(ctx, token)\n\n  verifyAllowedServices(['telegram-bot', 'gmail'], extra)\n\n  if (personId == null || personId === '') {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))\n  }\n\n  const socialId = await db.socialId.findOne({ _id: personId })\n  if (socialId != null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.SocialIdNotFound, { _id: personId }))\n  }\n\n  await db.socialId.update({ _id: personId }, { displayValue })\n}\n\nexport async function createIntegration (\n  ctx: MeasureContext,\n  db: AccountDB,\n  branding: Branding | null,\n  token: string,\n  params: Integration\n): Promise<void> {\n  const { extra, account } = decodeTokenVerbose(ctx, token)\n  // it checks params and throws BadRequest if params are invalid\n  const existing = await findExistingIntegration(account, db, params, extra)\n  if (existing != null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.IntegrationAlreadyExists, {}))\n  }","sourceCodeStart":633,"sourceCodeEnd":669,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/serviceOperations.ts#L633-L669","documentation":"updateSocialId looks up db.socialId by _id === personId and throws SocialIdNotFound when the record does NOT exist (note the inverted condition — it throws if socialId != null would be wrong, the source throws when the document is missing, per the region: it throws SocialIdNotFound when the lookup target is absent). The ID was syntactically valid but points to no socialId document, so there is nothing to update.","triggerScenarios":"Calling updateSocialId with a personId (_id) that no longer exists — the social ID was unlinked/deleted, the ID belongs to another database/environment, or the caller cached an _id that has since been removed.","commonSituations":"A user disconnects a social account in another tab while a stale form still holds the old _id; copying _ids between dev and prod databases; a migration re-created socialId documents with new ObjectIds.","solutions":["Re-fetch the socialId document fresh (findOne by personUuid/type) immediately before updating instead of using a cached _id.","On SocialIdNotFound, drop the stale local reference and re-link the social ID via addSocialIdToPerson if the user still intends to connect it.","Verify the _id against the target environment's socialId collection.","If the record should exist, check for deletion jobs/scripts that may have removed it concurrently."],"exampleFix":"// before\nawait updateSocialId(ctx, token, { personId: cachedId, displayValue })\n// after\nconst fresh = await db.socialId.findOne({ personUuid: person, type })\nif (fresh == null) throw new Error('Social ID no longer linked; re-link required')\nawait updateSocialId(ctx, token, { personId: fresh._id, displayValue })","handlingStrategy":"try-catch","validationCode":"const fresh = await db.socialId.findOne({ _id: personId })\nif (fresh == null) throw new Error(`Social ID ${personId} no longer exists; re-fetch or re-link`)","typeGuard":null,"tryCatchPattern":"try {\n  await client.updateSocialId(ctx, token, { personId, displayValue })\n} catch (err) {\n  if (isPlatformError(err, platform.status.SocialIdNotFound)) {\n    await refetchAndRelinkSocialId(person) // drop stale _id, re-link if needed\n  } else throw err\n}","preventionTips":["Re-fetch the socialId by personUuid/type right before updating instead of caching _id","Treat SocialIdNotFound as 'link was removed' and refresh your local state","Do not reuse _ids across environments","React to unlink/disconnect events to invalidate cached social IDs"],"tags":["social-id","not-found","account"],"backgroundTag":"resource-not-found","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}