Skip to content

Commit 00e6c56

Browse files
refactor(orchestration): move the shared error contract out of lib/workflows
OrchestrationErrorCode and statusForOrchestrationError are the contract every lib/[resource]/orchestration module returns against, but they lived inside the workflows module, so resource-neutral code (lib/folders) already had to import from a workflow path. Moved to lib/core/orchestration/types so the table, knowledge, workspace, and organization modules landing next don't cement that. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 53ea6a8 commit 00e6c56

13 files changed

Lines changed: 15 additions & 14 deletions

File tree

apps/sim/app/api/tools/deployments/deploy/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { assertWorkflowMutable, WorkflowLockedError } from '@sim/platform-authz/
33
import { type NextRequest, NextResponse } from 'next/server'
44
import { deploymentsDeployContract } from '@/lib/api/contracts/tools/deployments'
55
import { getValidationErrorMessage, parseRequest } from '@/lib/api/server'
6+
import { statusForOrchestrationError } from '@/lib/core/orchestration/types'
67
import { generateRequestId } from '@/lib/core/utils/request'
78
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
89
import { performFullDeploy } from '@/lib/workflows/orchestration'
9-
import { statusForOrchestrationError } from '@/lib/workflows/orchestration/types'
1010
import {
1111
authenticateDeploymentToolRequest,
1212
authorizeDeploymentWorkflow,

apps/sim/app/api/tools/deployments/promote/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { assertWorkflowMutable, WorkflowLockedError } from '@sim/platform-authz/
33
import { type NextRequest, NextResponse } from 'next/server'
44
import { deploymentsPromoteContract } from '@/lib/api/contracts/tools/deployments'
55
import { getValidationErrorMessage, parseRequest } from '@/lib/api/server'
6+
import { statusForOrchestrationError } from '@/lib/core/orchestration/types'
67
import { generateRequestId } from '@/lib/core/utils/request'
78
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
89
import { performActivateVersion } from '@/lib/workflows/orchestration'
9-
import { statusForOrchestrationError } from '@/lib/workflows/orchestration/types'
1010
import {
1111
authenticateDeploymentToolRequest,
1212
authorizeDeploymentWorkflow,

apps/sim/app/api/v1/workflows/[id]/deploy/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {
88
v1UndeployWorkflowContract,
99
} from '@/lib/api/contracts/v1/workflows'
1010
import { parseOptionalJsonBody, parseRequest } from '@/lib/api/server'
11+
import { statusForOrchestrationError } from '@/lib/core/orchestration/types'
1112
import { generateRequestId } from '@/lib/core/utils/request'
1213
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1314
import { captureServerEvent } from '@/lib/posthog/server'
1415
import { performFullDeploy, performFullUndeploy } from '@/lib/workflows/orchestration'
15-
import { statusForOrchestrationError } from '@/lib/workflows/orchestration/types'
1616
import { createApiResponse, getUserLimits } from '@/app/api/v1/logs/meta'
1717
import {
1818
checkRateLimit,

apps/sim/app/api/v1/workflows/[id]/rollback/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {
77
v1RollbackWorkflowContract,
88
} from '@/lib/api/contracts/v1/workflows'
99
import { parseOptionalJsonBody, parseRequest } from '@/lib/api/server'
10+
import { statusForOrchestrationError } from '@/lib/core/orchestration/types'
1011
import { generateRequestId } from '@/lib/core/utils/request'
1112
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1213
import { performActivateVersion } from '@/lib/workflows/orchestration'
13-
import { statusForOrchestrationError } from '@/lib/workflows/orchestration/types'
1414
import { findPreviousDeploymentVersion } from '@/lib/workflows/persistence/utils'
1515
import { createApiResponse, getUserLimits } from '@/app/api/v1/logs/meta'
1616
import {

apps/sim/app/api/workflows/[id]/deploy/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { eq } from 'drizzle-orm'
77
import type { NextRequest } from 'next/server'
88
import { updatePublicApiContract } from '@/lib/api/contracts/deployments'
99
import { parseRequest } from '@/lib/api/server'
10+
import { statusForOrchestrationError } from '@/lib/core/orchestration/types'
1011
import { generateRequestId } from '@/lib/core/utils/request'
1112
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1213
import { captureServerEvent } from '@/lib/posthog/server'
@@ -15,7 +16,6 @@ import {
1516
performFullDeploy,
1617
performFullUndeploy,
1718
} from '@/lib/workflows/orchestration'
18-
import { statusForOrchestrationError } from '@/lib/workflows/orchestration/types'
1919
import { validateWorkflowPermissions } from '@/lib/workflows/utils'
2020
import {
2121
checkNeedsRedeployment,

apps/sim/app/api/workflows/[id]/deployments/[version]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { and, eq } from 'drizzle-orm'
44
import type { NextRequest } from 'next/server'
55
import { updateDeploymentVersionMetadataContract } from '@/lib/api/contracts/deployments'
66
import { getValidationErrorMessage, parseRequest } from '@/lib/api/server'
7+
import { statusForOrchestrationError } from '@/lib/core/orchestration/types'
78
import { generateRequestId } from '@/lib/core/utils/request'
89
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
910
import { performActivateVersion } from '@/lib/workflows/orchestration'
10-
import { statusForOrchestrationError } from '@/lib/workflows/orchestration/types'
1111
import {
1212
getWorkflowDeploymentVersion,
1313
updateDeploymentVersionMetadata,

apps/sim/lib/workflows/orchestration/types.test.ts renamed to apps/sim/lib/core/orchestration/types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @vitest-environment node
33
*/
44
import { describe, expect, it } from 'vitest'
5-
import { statusForOrchestrationError } from '@/lib/workflows/orchestration/types'
5+
import { statusForOrchestrationError } from '@/lib/core/orchestration/types'
66

77
describe('statusForOrchestrationError', () => {
88
it.each([

apps/sim/lib/workflows/orchestration/types.ts renamed to apps/sim/lib/core/orchestration/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
export type OrchestrationErrorCode = 'validation' | 'not_found' | 'conflict' | 'internal'
22

33
/**
4-
* Maps an orchestration error code to its HTTP status. Shared by every route
5-
* surface (UI, v1, tool routes) so deployment errors map identically.
4+
* Transport-neutral failure classes returned by every `lib/[resource]/orchestration`
5+
* module, so the UI routes, the public API, and the copilot tools map the same
6+
* failure to the same status.
67
*/
78
export function statusForOrchestrationError(code: OrchestrationErrorCode | undefined): number {
89
if (code === 'validation') return 400

apps/sim/lib/folders/lifecycle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getPostgresErrorCode } from '@sim/utils/errors'
66
import { generateId } from '@sim/utils/id'
77
import { and, eq, isNull, min } from 'drizzle-orm'
88
import type { FolderCascadeCountsApi, FolderResourceType } from '@/lib/api/contracts/folders'
9+
import type { OrchestrationErrorCode } from '@/lib/core/orchestration/types'
910
import type { DbOrTx } from '@/lib/db/types'
1011
import {
1112
archiveFolderCascade,
@@ -19,7 +20,6 @@ import { folderResourceConfig } from '@/lib/folders/config'
1920
import { deduplicateFolderName } from '@/lib/folders/naming'
2021
import { wouldCreateFolderCycle } from '@/lib/folders/queries'
2122
import type { FolderMutationErrorCode } from '@/lib/folders/status'
22-
import type { OrchestrationErrorCode } from '@/lib/workflows/orchestration/types'
2323

2424
const logger = createLogger('FolderLifecycle')
2525

apps/sim/lib/folders/status.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OrchestrationErrorCode } from '@/lib/workflows/orchestration/types'
1+
import type { OrchestrationErrorCode } from '@/lib/core/orchestration/types'
22

33
/**
44
* Folder mutations can fail for one reason the shared orchestration vocabulary has no word

0 commit comments

Comments
 (0)