diff --git a/packages/cli-v3/src/entryPoints/dev-index-worker.ts b/packages/cli-v3/src/entryPoints/dev-index-worker.ts index da5c6ee750..f1bb86631f 100644 --- a/packages/cli-v3/src/entryPoints/dev-index-worker.ts +++ b/packages/cli-v3/src/entryPoints/dev-index-worker.ts @@ -13,18 +13,14 @@ import { } from "@trigger.dev/core/v3/workers"; import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler"; import { readFile } from "node:fs/promises"; -import sourceMapSupport from "source-map-support"; import { registerResources } from "../indexing/registerResources.js"; +import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js"; import { env } from "std-env"; import { normalizeImportPath } from "../utilities/normalizeImportPath.js"; import { detectRuntimeVersion } from "@trigger.dev/core/v3/build"; import { schemaToJsonSchema } from "@trigger.dev/schema-to-json"; -sourceMapSupport.install({ - handleUncaughtExceptions: false, - environment: "node", - hookRequire: false, -}); +installSourceMapSupport(); process.on("uncaughtException", function (error, origin) { if (error instanceof Error) { diff --git a/packages/cli-v3/src/entryPoints/dev-run-worker.ts b/packages/cli-v3/src/entryPoints/dev-run-worker.ts index 7cd88ab5a9..8847dca4ac 100644 --- a/packages/cli-v3/src/entryPoints/dev-run-worker.ts +++ b/packages/cli-v3/src/entryPoints/dev-run-worker.ts @@ -63,17 +63,13 @@ import { import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc"; import { readFile } from "node:fs/promises"; import { setInterval, setTimeout } from "node:timers/promises"; -import sourceMapSupport from "source-map-support"; import { env } from "std-env"; import { normalizeImportPath } from "../utilities/normalizeImportPath.js"; +import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js"; import { VERSION } from "../version.js"; import { promiseWithResolvers } from "@trigger.dev/core/utils"; -sourceMapSupport.install({ - handleUncaughtExceptions: false, - environment: "node", - hookRequire: false, -}); +installSourceMapSupport(); process.on("uncaughtException", function (error, origin) { logError("Uncaught exception", { error, origin }); diff --git a/packages/cli-v3/src/entryPoints/managed-index-worker.ts b/packages/cli-v3/src/entryPoints/managed-index-worker.ts index 5ff9f1b62e..cd224eb909 100644 --- a/packages/cli-v3/src/entryPoints/managed-index-worker.ts +++ b/packages/cli-v3/src/entryPoints/managed-index-worker.ts @@ -13,18 +13,14 @@ import { } from "@trigger.dev/core/v3/workers"; import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler"; import { readFile } from "node:fs/promises"; -import sourceMapSupport from "source-map-support"; import { registerResources } from "../indexing/registerResources.js"; +import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js"; import { env } from "std-env"; import { normalizeImportPath } from "../utilities/normalizeImportPath.js"; import { detectRuntimeVersion } from "@trigger.dev/core/v3/build"; import { schemaToJsonSchema } from "@trigger.dev/schema-to-json"; -sourceMapSupport.install({ - handleUncaughtExceptions: false, - environment: "node", - hookRequire: false, -}); +installSourceMapSupport(); process.on("uncaughtException", function (error, origin) { if (error instanceof Error) { diff --git a/packages/cli-v3/src/entryPoints/managed-run-worker.ts b/packages/cli-v3/src/entryPoints/managed-run-worker.ts index f1512f27f0..963597bf15 100644 --- a/packages/cli-v3/src/entryPoints/managed-run-worker.ts +++ b/packages/cli-v3/src/entryPoints/managed-run-worker.ts @@ -63,17 +63,13 @@ import { import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc"; import { readFile } from "node:fs/promises"; import { setInterval, setTimeout } from "node:timers/promises"; -import sourceMapSupport from "source-map-support"; import { env } from "std-env"; import { normalizeImportPath } from "../utilities/normalizeImportPath.js"; +import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js"; import { VERSION } from "../version.js"; import { promiseWithResolvers } from "@trigger.dev/core/utils"; -sourceMapSupport.install({ - handleUncaughtExceptions: false, - environment: "node", - hookRequire: false, -}); +installSourceMapSupport(); process.on("uncaughtException", function (error, origin) { console.error("Uncaught exception", { error, origin }); diff --git a/packages/cli-v3/src/utilities/installSourceMapSupport.ts b/packages/cli-v3/src/utilities/installSourceMapSupport.ts new file mode 100644 index 0000000000..135e520408 --- /dev/null +++ b/packages/cli-v3/src/utilities/installSourceMapSupport.ts @@ -0,0 +1,32 @@ +import sourceMapSupport from "source-map-support"; + +/** + * Installs source-map-support with a workaround for Bun's source map handling. + * + * Bun's runtime can produce source maps with column values of -1, which causes + * source-map@0.6.1 (used by source-map-support) to throw: + * "Column must be greater than or equal to 0, got -1" + * + * This wraps the prepareStackTrace hook so that if source map processing fails, + * it falls back to default stack trace formatting instead of crashing. + * + * See: https://github.com/oven-sh/bun/issues/8087 + */ +export function installSourceMapSupport() { + sourceMapSupport.install({ + handleUncaughtExceptions: false, + environment: "node", + hookRequire: false, + }); + + const _prepareStackTrace = (Error as any).prepareStackTrace; + if (_prepareStackTrace) { + (Error as any).prepareStackTrace = (error: Error, stackTraces: NodeJS.CallSite[]) => { + try { + return _prepareStackTrace(error, stackTraces); + } catch { + return `${error}\n` + stackTraces.map((s) => ` at ${s}`).join("\n"); + } + }; + } +}