Skip to content

Commit 4dba966

Browse files
capajclaude
andcommitted
fix: handle invalid source map columns in Bun runtime
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 installed by source-map-support so that if source map processing fails, it falls back to default stack trace formatting instead of crashing the indexer/worker. Extracted into a shared installSourceMapSupport utility used by all 4 entry points (dev/managed index/run workers). Fixes #3045 See: oven-sh/bun#8087 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2462c80 commit 4dba966

File tree

5 files changed

+40
-24
lines changed

5 files changed

+40
-24
lines changed

packages/cli-v3/src/entryPoints/dev-index-worker.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ import {
1313
} from "@trigger.dev/core/v3/workers";
1414
import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler";
1515
import { readFile } from "node:fs/promises";
16-
import sourceMapSupport from "source-map-support";
1716
import { registerResources } from "../indexing/registerResources.js";
17+
import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js";
1818
import { env } from "std-env";
1919
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
2020
import { detectRuntimeVersion } from "@trigger.dev/core/v3/build";
2121
import { schemaToJsonSchema } from "@trigger.dev/schema-to-json";
2222

23-
sourceMapSupport.install({
24-
handleUncaughtExceptions: false,
25-
environment: "node",
26-
hookRequire: false,
27-
});
23+
installSourceMapSupport();
2824

2925
process.on("uncaughtException", function (error, origin) {
3026
if (error instanceof Error) {

packages/cli-v3/src/entryPoints/dev-run-worker.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,13 @@ import {
6363
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
6464
import { readFile } from "node:fs/promises";
6565
import { setInterval, setTimeout } from "node:timers/promises";
66-
import sourceMapSupport from "source-map-support";
6766
import { env } from "std-env";
6867
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
68+
import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js";
6969
import { VERSION } from "../version.js";
7070
import { promiseWithResolvers } from "@trigger.dev/core/utils";
7171

72-
sourceMapSupport.install({
73-
handleUncaughtExceptions: false,
74-
environment: "node",
75-
hookRequire: false,
76-
});
72+
installSourceMapSupport();
7773

7874
process.on("uncaughtException", function (error, origin) {
7975
logError("Uncaught exception", { error, origin });

packages/cli-v3/src/entryPoints/managed-index-worker.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ import {
1313
} from "@trigger.dev/core/v3/workers";
1414
import { sendMessageInCatalog, ZodSchemaParsedError } from "@trigger.dev/core/v3/zodMessageHandler";
1515
import { readFile } from "node:fs/promises";
16-
import sourceMapSupport from "source-map-support";
1716
import { registerResources } from "../indexing/registerResources.js";
17+
import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js";
1818
import { env } from "std-env";
1919
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
2020
import { detectRuntimeVersion } from "@trigger.dev/core/v3/build";
2121
import { schemaToJsonSchema } from "@trigger.dev/schema-to-json";
2222

23-
sourceMapSupport.install({
24-
handleUncaughtExceptions: false,
25-
environment: "node",
26-
hookRequire: false,
27-
});
23+
installSourceMapSupport();
2824

2925
process.on("uncaughtException", function (error, origin) {
3026
if (error instanceof Error) {

packages/cli-v3/src/entryPoints/managed-run-worker.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,13 @@ import {
6363
import { ZodIpcConnection } from "@trigger.dev/core/v3/zodIpc";
6464
import { readFile } from "node:fs/promises";
6565
import { setInterval, setTimeout } from "node:timers/promises";
66-
import sourceMapSupport from "source-map-support";
6766
import { env } from "std-env";
6867
import { normalizeImportPath } from "../utilities/normalizeImportPath.js";
68+
import { installSourceMapSupport } from "../utilities/installSourceMapSupport.js";
6969
import { VERSION } from "../version.js";
7070
import { promiseWithResolvers } from "@trigger.dev/core/utils";
7171

72-
sourceMapSupport.install({
73-
handleUncaughtExceptions: false,
74-
environment: "node",
75-
hookRequire: false,
76-
});
72+
installSourceMapSupport();
7773

7874
process.on("uncaughtException", function (error, origin) {
7975
console.error("Uncaught exception", { error, origin });
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import sourceMapSupport from "source-map-support";
2+
3+
/**
4+
* Installs source-map-support with a workaround for Bun's source map handling.
5+
*
6+
* Bun's runtime can produce source maps with column values of -1, which causes
7+
* source-map@0.6.1 (used by source-map-support) to throw:
8+
* "Column must be greater than or equal to 0, got -1"
9+
*
10+
* This wraps the prepareStackTrace hook so that if source map processing fails,
11+
* it falls back to default stack trace formatting instead of crashing.
12+
*
13+
* See: https://github.com/oven-sh/bun/issues/8087
14+
*/
15+
export function installSourceMapSupport() {
16+
sourceMapSupport.install({
17+
handleUncaughtExceptions: false,
18+
environment: "node",
19+
hookRequire: false,
20+
});
21+
22+
const _prepareStackTrace = (Error as any).prepareStackTrace;
23+
if (_prepareStackTrace) {
24+
(Error as any).prepareStackTrace = (error: Error, stackTraces: NodeJS.CallSite[]) => {
25+
try {
26+
return _prepareStackTrace(error, stackTraces);
27+
} catch {
28+
return `${error}\n` + stackTraces.map((s) => ` at ${s}`).join("\n");
29+
}
30+
};
31+
}
32+
}

0 commit comments

Comments
 (0)