hcengineering/platform · error

Workspace not found

Error message

Workspace not found

What it means

getTransactorEndpoint calls accountClient.selectWorkspace('', kind, externalRegions) in a retry loop. If the account service responds with no workspace (undefined result), the function throws 'Workspace not found'. Notably, because this error is thrown inside the try block, it is caught and only rethrown when the timeout has elapsed — otherwise it is treated like a connection error and only retried when err.cause.code is a connection error, otherwise rethrown immediately on the next loop iteration check.

Source

Thrown at foundations/server/packages/client/src/account.ts:59

 *
 * @param token - The authorization token.
 * @param kind - The type of endpoint to retrieve. Can be 'internal', 'external', or 'byregion'. Defaults to 'byregion'.
 * @param timeout - The timeout duration in milliseconds. Defaults to -1 (no timeout).
 * @returns A promise that resolves to the transactor endpoint URL as a string.
 * @throws Will throw an error if the request fails or if the timeout is reached.
 */
export async function getTransactorEndpoint (
  token: string,
  kind: 'internal' | 'external' | 'byregion' = 'byregion',
  timeout: number = -1
): Promise<string> {
  const accountClient = getAccountClient(token, 30000)
  const st = Date.now()
  while (true) {
    try {
      const workspaceInfo = await accountClient.selectWorkspace('', kind, externalRegions)
      if (workspaceInfo === undefined) {
        throw new Error('Workspace not found')
      }
      return workspaceInfo.endpoint
    } catch (err: any) {
      if (timeout > 0 && st + timeout < Date.now()) {
        // Timeout happened
        throw err
      }
      if (connectionErrorCodes.includes(err?.cause?.code)) {
        await new Promise<void>((resolve) => setTimeout(resolve, 1000))
      } else {
        throw err
      }
    }
  }
}

export function withRetry<P extends any[], T> (
  f: (...params: P) => Promise<T>,

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Verify the token is valid and belongs to a user/workspace that exists
  2. Call with a positive timeout (e.g. 30000) so transient 'no workspace yet' states are retried instead of thrown immediately
  3. Remove/loosen the externalRegions restriction or pass a kind matching an available workspace
  4. Check the account service data to confirm the workspace exists and is active

Example fix

// before
const ep = await getTransactorEndpoint(token) // no timeout; undefined workspace throws fast
// after
const ep = await getTransactorEndpoint(token, 'byregion', 60000) // wait up to 60s for provisioning
Defensive patterns

Strategy: retry

Validate before calling

// ensure a positive timeout so transient 'no workspace' states are retried rather than thrown
const timeoutMs = 30000
if (!token || typeof token !== 'string' || token.length < 10) throw new Error('Invalid token')

Type guard

function isWorkspaceInfo(v: unknown): v is { endpoint: string } {
  return !!v && typeof v === 'object' && typeof (v as any).endpoint === 'string'
}

Try / catch

try {
  const endpoint = await getTransactorEndpoint(token, 'byregion', 30000)
} catch (err) {
  if (err.message === 'Workspace not found') {
    // token has no workspace, or regions filter excludes everything: check account/provisioning
  }
  throw err
}

Prevention

When it happens

Trigger: Calling getTransactorEndpoint with a token that has no associated workspace; the account service returns no workspace for the given kind ('internal'/'external'/'byregion') and externalRegions; account service still provisioning (during signup) so selectWorkspace returns undefined.

Common situations: Token from a user whose workspace was deleted; region filters (externalRegions) that exclude all available workspaces; calling immediately after workspace creation before the account service has propagated it; wrong auth token or expired session.

Related errors


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