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
20 changes: 8 additions & 12 deletions packages/cli/src/lib/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,23 +429,19 @@ const LIBRARY_EXCLUDED_INTEGRATIONS = new Set([
]);

/**
* Check whether `util.getSystemErrorMap` exists at setup time.
* Whether `util.getSystemErrorMap` is available at runtime.
*
* Bun does not implement this Node.js API, which the SDK's NodeSystemError
* integration uses in its `processEvent` hook. When missing, the hook crashes
* during event processing instead of sending the error report (CLI-K1).
*
* Checked once at module load so the integration filter is a simple boolean.
* We detect bun via `process.versions.bun` rather than probing `node:util`
* directly. In a bun-compiled binary, `_require("node:util")` resolves to the
* bundled (build-time) Node.js util, which has `getSystemErrorMap` — even
* though bun's own runtime `node:util` does not. Checking the bun version
* is always accurate at runtime regardless of how the code was bundled (CLI-3HF).
*/
const hasGetSystemErrorMap = (() => {
// oxlint-disable-next-line sentry-cli/no-silent-catch -- grandfathered silent catch — see #1531; drain by adding log.debug()/log.warn() or re-throwing.
try {
// Dynamic require to avoid bundler issues — the check only matters at runtime
const util = _require("node:util") as Record<string, unknown>;
return typeof util.getSystemErrorMap === "function";
} catch {
return false;
}
})();
const hasGetSystemErrorMap = !process.versions.bun;

/** Current beforeExit handler, tracked so it can be replaced on re-init */
let currentBeforeExitHandler: (() => void) | null = null;
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/test/lib/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ describe("initSentry", () => {
const client = initSentry(true);
expect(client?.getOptions().release).toBe("0.0.0-dev");
});

test("includes NodeSystemError integration on Node.js (not bun)", () => {
// hasGetSystemErrorMap = !process.versions.bun; on Node.js process.versions.bun
// is undefined, so NodeSystemError should be included. This guards against
// regressions where the integration is wrongly excluded on Node.js (CLI-3HF).
const client = initSentry(true);
const integration = client?.getIntegrationByName("NodeSystemError");
expect(integration).toBeDefined();
});
});

describe("withTelemetry", () => {
Expand Down
Loading