hcengineering/platform · warning · PlatformError

BadRequest

BadRequest

Error message

BadRequest

What it means

BadRequest is thrown by updateWorkspaceInfo when required parameters are missing or empty: workspaceUuid is null/empty string, or event is null. This check runs after the service-allowlist check, so the caller is authorized but sent an incomplete payload. It signals malformed request data rather than an auth or state problem.

Source

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

  branding: Branding | null,
  token: string,
  params: {
    workspaceUuid: WorkspaceUuid
    event: WorkspaceEvent
    version: Data<Version> // A worker version
    progress: number
    message?: string
  }
): Promise<void> {
  const { workspaceUuid, event, version, message } = params

  const { extra } = decodeTokenVerbose(ctx, token)
  if (!['workspace', 'tool'].includes(extra?.service)) {
    throw new PlatformError(new Status(Severity.ERROR, platform.status.Forbidden, {}))
  }

  if (workspaceUuid == null || workspaceUuid === '' || event == null) {
    throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))
  }

  let progress = params.progress

  const wsExists = await db.workspace.exists({ uuid: workspaceUuid })
  if (!wsExists) {
    throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspaceUuid }))
  }
  progress = Math.round(progress)

  const ts = Date.now()
  const update: Partial<WorkspaceStatus> = {}
  const wsUpdate: Partial<Workspace> = {}
  const query: Query<WorkspaceStatus> = { workspaceUuid }

  // Only read status for certain events because it is not needed for others
  // and it interferes with status updates when concurrency is high
  let wsStatus: WorkspaceStatus | null = null

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Validate workspaceUuid is a non-empty UUID string and event is non-null before calling updateWorkspaceInfo.
  2. Ensure the workspace was created and its UUID was received (await the create call) before sending status updates.
  3. Check serialization of the params object (no dropped fields from spread/JSON transforms).
  4. Return/log a clear client-side error instead of calling the API with incomplete data.

Example fix

// before
await accountClient.updateWorkspaceInfo(ctx, token, { workspaceUuid: wsId, event })

// after
if (!wsId || event == null) {
  throw new Error(`updateWorkspaceInfo requires workspaceUuid and event, got wsId=${wsId}, event=${event}`)
}
await accountClient.updateWorkspaceInfo(ctx, token, { workspaceUuid: wsId, event })
Defensive patterns

Strategy: validation

Validate before calling

// Validate required params before the API call
if (workspaceUuid == null || workspaceUuid === '') {
  throw new Error('workspaceUuid must be a non-empty UUID')
}
if (event == null) {
  throw new Error('event is required for updateWorkspaceInfo')
}

Type guard

function isValidUpdatePayload(p: UpdateWorkspaceInfoParams): p is UpdateWorkspaceInfoParams & { workspaceUuid: string; event: WorkspaceEvent } {
  return p.workspaceUuid != null && p.workspaceUuid !== '' && p.event != null
}

Try / catch

try {
  await updateWorkspaceInfo(ctx, token, params)
} catch (err) {
  if (err instanceof PlatformError && err.status.code === platform.status.BadRequest) {
    log.error('updateWorkspaceInfo payload incomplete', { params })
    return
  }
  throw err
}

Prevention

When it happens

Trigger: Passing workspaceUuid as '' or undefined, or omitting the event field, when calling updateWorkspaceInfo — e.g. an uninitialized workspace record ID, a variable not yet assigned, or an event enum/value that failed to serialize.

Common situations: Callers constructing the params object dynamically and skipping empty workspaceUuid; race where a workspace-create hasn't returned an ID yet; TypeScript strict mode off letting undefined through; event produced by a mapping function returning null on unknown workspace states.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


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