hcengineering/platform · error · PlatformError

AccountNotFound

AccountNotFound

Error message

AccountNotFound

What it means

AccountNotFound is thrown by updateWorkspaceRoleBySocialKey when the provided socialKey does not resolve to any social account in the database. The service looks up getSocialIdByKey with the lowercased socialKey, and if no row matches, it cannot determine the target account for the role update, so it aborts with this PlatformError status. It indicates the caller supplied an identifier for an account that does not exist (or was never linked).

Source

Thrown at server/account/src/serviceOperations.ts:245

  branding: Branding | null,
  token: string,
  params: {
    socialKey: string
    targetRole: AccountRole
  }
): Promise<void> {
  const { socialKey, targetRole } = params

  if (socialKey == null || socialKey === '' || targetRole == null || !assignableRoles.includes(targetRole)) {
    throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))
  }

  const { extra } = decodeTokenVerbose(ctx, token)
  verifyAllowedServices(['workspace', 'tool'], extra)

  const socialId = await getSocialIdByKey(db, socialKey.toLowerCase() as PersonId)
  if (socialId == null) {
    throw new PlatformError(new Status(Severity.ERROR, platform.status.AccountNotFound, {}))
  }

  await updateWorkspaceRole(ctx, db, branding, token, { targetAccount: socialId.personUuid as AccountUuid, targetRole })
}

/**
 * Retrieves one workspace for which there are things to process.
 *
 * Workspace is provided for 30seconds. This timeout is reset
 * on every progress update.
 * If no progress is reported for the workspace during this time,
 * it will become available again to be processed by another executor.
 */
export async function getPendingWorkspace (
  ctx: MeasureContext,
  db: AccountDB,
  branding: Branding | null,
  token: string,

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Verify the socialKey value is the exact key stored in the account's social_id table (query by key = lowercased value) before calling the API.
  2. Ensure the social account is actually registered/linked via the signup/link flow before attempting a role update.
  3. Check you are pointing at the correct database/environment (staging vs prod) where the account exists.
  4. Handle the PlatformError with status AccountNotFound in the caller and surface a 'create account first' flow instead of retrying.

Example fix

// before
await accountClient.updateWorkspaceRoleBySocialKey(ctx, token, socialKey, role)

// after
const normalizedKey = socialKey.trim().toLowerCase()
const existing = await findSocialIdByKey(db, normalizedKey)
if (existing == null) {
  await accountClient.signupAndLinkSocial(ctx, token, normalizedKey) // ensure account exists first
}
await accountClient.updateWorkspaceRoleBySocialKey(ctx, token, normalizedKey, role)
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the social key is normalized and resolvable before the call
const normalizedKey = socialKey.trim().toLowerCase()
if (!normalizedKey) throw new Error('socialKey is required')
const socialId = await findSocialIdByKey(db, normalizedKey)
if (socialId == null) throw new Error(`No account linked to socialKey ${normalizedKey}; register/link the account first`)

Type guard

function hasSocialAccount(v: SocialId | null | undefined): v is SocialId {
  return v != null && typeof v.personUuid === 'string'
}

Try / catch

try {
  await updateWorkspaceRoleBySocialKey(ctx, db, branding, token, socialKey, targetRole)
} catch (err) {
  if (err instanceof PlatformError && err.status.code === platform.status.AccountNotFound) {
    // prompt user to sign up / link social account
    return
  }
  throw err
}

Prevention

When it happens

Trigger: Calling updateWorkspaceRoleBySocialKey with a socialKey string that has no corresponding social_id row in the account database: the key is wrong/typo'd, the key was never registered, the social account was deleted, or the key case differed pre-normalization (the function lowercases it, so mixed-case stored keys will not match).

Common situations: Workspace provisioning flows where a tool service passes a social key obtained from an external SSO provider before that account finished linking in Huly; stale keys cached on the client after account removal; passing an email or external user id instead of the actual social key; environment mismatch (key exists in prod DB but not in the staging DB being called).

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/25a9f33c67b35498. Report an issue: GitHub.