{"record":{"id":"06219dfa7440289b","repo":"hcengineering/platform","slug":"unarchive-allowed-only-for-archived-workspaces","errorCode":null,"errorMessage":"Unarchive allowed only for archived workspaces","messagePattern":"Unarchive allowed only for archived workspaces","errorType":"exception","errorClass":"PlatformError","httpStatus":null,"severity":"error","filePath":"server/account/src/serviceOperations.ts","lineNumber":180,"sourceCode":"        update.mode = 'pending-deletion'\n        update.processingAttempts = 0\n        update.processingProgress = 0\n        update.lastProcessingTime = Date.now() - processingTimeoutMs // To not wait for next step\n        break\n      case 'archive':\n        if (!isActiveMode(workspace.status.mode)) {\n          throw new PlatformError(unknownError('Archiving allowed only for active workspaces'))\n        }\n\n        update.mode = 'archiving-pending-backup'\n        update.processingAttempts = 0\n        update.processingProgress = 0\n        update.lastProcessingTime = Date.now() - processingTimeoutMs // To not wait for next step\n        break\n      case 'unarchive':\n        if (event === 'unarchive') {\n          if (workspace.status.mode !== 'archived') {\n            throw new PlatformError(unknownError('Unarchive allowed only for archived workspaces'))\n          }\n        }\n\n        update.mode = 'pending-restore'\n        update.processingAttempts = 0\n        update.processingProgress = 0\n        update.lastProcessingTime = Date.now() - processingTimeoutMs // To not wait for next step\n        break\n      case 'migrate-to': {\n        if (!isActiveMode(workspace.status.mode)) {\n          return false\n        }\n        if (params.length !== 1 && params[0] == null) {\n          throw new PlatformError(unknownError('Invalid region passed to migrate operation'))\n        }\n        const regions = getRegions()\n        if (regions.find((it) => it.region === params[0]) === undefined) {\n          throw new PlatformError(unknownError('Invalid region passed to migrate operation'))","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/serviceOperations.ts#L162-L198","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check workspace.status.mode before calling and only issue 'unarchive' when it equals 'archived'","If the workspace is already active, the unarchive already happened — treat the call as a no-op instead of retrying","If the workspace is stuck in 'pending-restore', wait for processing to finish or use 'reset-attempts' to unblock processing before any other operation"],"exampleFix":"// before\nawait performWorkspaceOperation(ctx, db, 'unarchive', workspaceUuid)\n// after\nconst ws = await db.workspaceStatus.findOne({ workspaceUuid })\nif (ws != null && ws.status.mode === 'archived') {\n  await performWorkspaceOperation(ctx, db, 'unarchive', workspaceUuid)\n}","handlingStrategy":"validation","validationCode":"const ws = await db.workspaceStatus.findOne({ workspaceUuid })\nif (ws == null || ws.status.mode !== 'archived') {\n  throw new Error(`Workspace ${workspaceUuid} is not archived (mode=${ws?.status.mode})`)\n}","typeGuard":"function isArchived(ws: Workspace): boolean {\n  return ws.status.mode === 'archived'\n}","tryCatchPattern":"try {\n  await performWorkspaceOperation(ctx, db, 'unarchive', workspaceUuid)\n} catch (err) {\n  if (err instanceof PlatformError && err.message.includes('Unarchive allowed only for archived workspaces')) {\n    // treat as already-restored / no-op\n  } else throw err\n}","preventionTips":["Always fetch current workspace status before issuing state-transition operations","Treat unarchive as idempotent: skip when mode is already 'active'","Avoid queueing archive/unarchive back-to-back without awaiting completion of processing"],"tags":["workspace","state-machine","invalid-operation"],"backgroundTag":"invalid-workspace-state-transition","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}