Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/migrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
working-directory: ./packages/db
env:
DATABASE_URL: ${{ github.ref == 'refs/heads/main' && secrets.DATABASE_URL || github.ref == 'refs/heads/dev' && secrets.DEV_DATABASE_URL || secrets.STAGING_DATABASE_URL }}
run: bunx drizzle-kit migrate --config=./drizzle.config.ts
run: bun run ./scripts/migrate.ts
42 changes: 41 additions & 1 deletion apps/sim/lib/workflows/executor/execution-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { createLogger } from '@sim/logger'
import { getErrorMessage } from '@sim/utils/errors'
import { filterUndefined } from '@sim/utils/object'
import { mergeSubblockStateWithValues } from '@sim/workflow-persistence/subblocks'
import type { Edge } from 'reactflow'
import { z } from 'zod'
Expand Down Expand Up @@ -39,6 +40,45 @@ const logger = createLogger('ExecutionCore')

const EnvVarsSchema = z.record(z.string(), z.string())

/**
* Surfaces the underlying driver error from a wrapped error chain.
*
* Drizzle wraps the original `postgres`/Node driver error as `error.cause`,
* which the logger's Error serializer drops (it only emits own-enumerable
* keys). Walking the `cause` chain and preferring the first error carrying a
* `code` exposes the diagnostic fields — notably the Postgres `code` — that
* distinguish a connection drop (`08006`), a rejected connection (`53300`),
* and a statement timeout (`57014`) behind an opaque "Failed query" message.
*/
function describeErrorCause(error: unknown): Record<string, unknown> | undefined {
try {
let current: unknown = error instanceof Error ? error.cause : undefined
let driver: (Error & Record<string, unknown>) | undefined
for (let depth = 0; depth < 10 && current instanceof Error; depth++) {
const candidate = current as Error & Record<string, unknown>
if (!driver) driver = candidate
if (candidate.code !== undefined) {
driver = candidate
break
}
current = candidate.cause
}
if (!driver) return undefined
return filterUndefined({
name: driver.name,
message: driver.message,
code: driver.code,
severity: driver.severity,
detail: driver.detail,
routine: driver.routine,
errno: driver.errno,
syscall: driver.syscall,
})
} catch {
return undefined
}
}

export interface ExecuteWorkflowCoreOptions {
snapshot: ExecutionSnapshot
callbacks: ExecutionCallbacks
Expand Down Expand Up @@ -681,7 +721,7 @@ export async function executeWorkflowCore(

return result
} catch (error: unknown) {
logger.error(`[${requestId}] Execution failed:`, error)
logger.error(`[${requestId}] Execution failed:`, error, { cause: describeErrorCause(error) })

await waitForLifecycleCallbacks()

Expand Down
1 change: 1 addition & 0 deletions packages/db/scripts/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (!url) {
const client = postgres(url, { max: 1, connect_timeout: 10 })

try {
await client`SET statement_timeout = 0`
await migrate(drizzle(client), { migrationsFolder: './migrations' })
console.log('Migrations applied successfully.')
} catch (error) {
Expand Down
Loading