hcengineering/platform · error · PlatformError

Unarchive allowed only for archived workspaces

Error message

Unarchive allowed only for archived workspaces

What it means

This error is thrown by performWorkspaceOperation when an 'unarchive' workspace operation is requested for a workspace whose status.mode is not 'archived'. The account service only permits restoring a workspace from the archived state; unarchiving an active, deleting, or already-restoring workspace is invalid. It is surfaced as an unknown PlatformError with the given message.

Source

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

        update.mode = 'pending-deletion'
        update.processingAttempts = 0
        update.processingProgress = 0
        update.lastProcessingTime = Date.now() - processingTimeoutMs // To not wait for next step
        break
      case 'archive':
        if (!isActiveMode(workspace.status.mode)) {
          throw new PlatformError(unknownError('Archiving allowed only for active workspaces'))
        }

        update.mode = 'archiving-pending-backup'
        update.processingAttempts = 0
        update.processingProgress = 0
        update.lastProcessingTime = Date.now() - processingTimeoutMs // To not wait for next step
        break
      case 'unarchive':
        if (event === 'unarchive') {
          if (workspace.status.mode !== 'archived') {
            throw new PlatformError(unknownError('Unarchive allowed only for archived workspaces'))
          }
        }

        update.mode = 'pending-restore'
        update.processingAttempts = 0
        update.processingProgress = 0
        update.lastProcessingTime = Date.now() - processingTimeoutMs // To not wait for next step
        break
      case 'migrate-to': {
        if (!isActiveMode(workspace.status.mode)) {
          return false
        }
        if (params.length !== 1 && params[0] == null) {
          throw new PlatformError(unknownError('Invalid region passed to migrate operation'))
        }
        const regions = getRegions()
        if (regions.find((it) => it.region === params[0]) === undefined) {
          throw new PlatformError(unknownError('Invalid region passed to migrate operation'))

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Check workspace.status.mode before calling and only issue 'unarchive' when it equals 'archived'
  2. If the workspace is already active, the unarchive already happened — treat the call as a no-op instead of retrying
  3. If the workspace is stuck in 'pending-restore', wait for processing to finish or use 'reset-attempts' to unblock processing before any other operation

Example fix

// before
await performWorkspaceOperation(ctx, db, 'unarchive', workspaceUuid)
// after
const ws = await db.workspaceStatus.findOne({ workspaceUuid })
if (ws != null && ws.status.mode === 'archived') {
  await performWorkspaceOperation(ctx, db, 'unarchive', workspaceUuid)
}
Defensive patterns

Strategy: validation

Validate before calling

const ws = await db.workspaceStatus.findOne({ workspaceUuid })
if (ws == null || ws.status.mode !== 'archived') {
  throw new Error(`Workspace ${workspaceUuid} is not archived (mode=${ws?.status.mode})`)
}

Type guard

function isArchived(ws: Workspace): boolean {
  return ws.status.mode === 'archived'
}

Try / catch

try {
  await performWorkspaceOperation(ctx, db, 'unarchive', workspaceUuid)
} catch (err) {
  if (err instanceof PlatformError && err.message.includes('Unarchive allowed only for archived workspaces')) {
    // treat as already-restored / no-op
  } else throw err
}

Prevention

When it happens

Trigger: Calling the workspace 'unarchive' operation (e.g. via performWorkspaceOperation with event='unarchive') on a workspace whose status.mode is anything other than 'archived' — for example the workspace is active, archived already restored to 'pending-restore', or mid-deletion.

Common situations: Double-invoking an unarchive request (retry after a first successful call that already moved the workspace to pending-restore); client state assuming a workspace is archived when it is actually active; tooling scripts that archive+unarchive in sequence where the archive did not complete before unarchive was issued.

Related errors


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