Skip to content

Commit f04a0dc

Browse files
logaretmclaude
andauthored
fix(profiling-node): Fix NODE_VERSION rendered as [object Object] in warning (#19788)
I found this while working on `no-base-to-string` rule, this is the only valid violation, the rest are buggy. ## Summary - `NODE_VERSION` is a `SemVer` object (`{ major, minor, patch }`) from `parseSemver()` with no custom `toString()`. Interpolating it in a template literal produced `[object Object]` instead of the actual version number. - Since the surrounding check is `![16, 18, 20, 22, 24].includes(NODE_MAJOR)`, it makes more sense to log `NODE_MAJOR` (a number) in the warning message anyway. - Added a test verifying that `NODE_VERSION` has no custom `toString()` to prevent future misuse. ## Test plan - [x] Added unit test confirming `NODE_VERSION` stringifies as `[object Object]` - [x] Existing profiling-node tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Closes #19789 (added automatically) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 81d1b97 commit f04a0dc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/profiling-node/src/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import type { NodeClient, NodeOptions } from '@sentry/node';
1616
import { CpuProfilerBindings, ProfileFormat, type RawThreadCpuProfile } from '@sentry-internal/node-cpu-profiler';
1717
import { DEBUG_BUILD } from './debug-build';
18-
import { NODE_MAJOR, NODE_VERSION } from './nodeVersion';
18+
import { NODE_MAJOR } from './nodeVersion';
1919
import { MAX_PROFILE_DURATION_MS, maybeProfileSpan, stopSpanProfile } from './spanProfileUtils';
2020
import {
2121
addProfilesToEnvelope,
@@ -634,7 +634,7 @@ export const _nodeProfilingIntegration = ((): ProfilingIntegration<NodeClient> =
634634
consoleSandbox(() => {
635635
// eslint-disable-next-line no-console
636636
console.warn(
637-
`[Sentry Profiling] You are using a Node.js version that does not have prebuilt binaries (${NODE_VERSION}).`,
637+
`[Sentry Profiling] You are using a Node.js version that does not have prebuilt binaries (${NODE_MAJOR}).`,
638638
'The @sentry/profiling-node package only has prebuilt support for the following LTS versions of Node.js: 16, 18, 20, 22, 24.',
639639
'To use the @sentry/profiling-node package with this version of Node.js, you will need to compile the native addon from source.',
640640
'See: https://github.com/getsentry/sentry-javascript/tree/develop/packages/profiling-node#building-the-package-from-source',

packages/profiling-node/test/integration.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { NodeClientOptions } from '@sentry/node/build/types/types';
55
import { CpuProfilerBindings } from '@sentry-internal/node-cpu-profiler';
66
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
77
import { _nodeProfilingIntegration } from '../src/integration';
8+
import { NODE_VERSION } from '../src/nodeVersion';
89

910
function makeLegacySpanProfilingClient(): [Sentry.NodeClient, Transport] {
1011
const integration = _nodeProfilingIntegration();
@@ -984,6 +985,16 @@ describe('ProfilingIntegration', () => {
984985
});
985986
});
986987

988+
describe('NODE_VERSION', () => {
989+
it('is a plain object without a custom toString', () => {
990+
// NODE_VERSION is a SemVer object from parseSemver — it has no custom toString().
991+
// Code should never interpolate it directly in a template literal.
992+
// Use process.versions.node or format the components manually instead.
993+
expect(`${NODE_VERSION}`).toBe('[object Object]');
994+
expect(`${NODE_VERSION.major}.${NODE_VERSION.minor}.${NODE_VERSION.patch}`).toMatch(/^\d+\.\d+\.\d+$/);
995+
});
996+
});
997+
987998
describe('Legacy vs Current API compat', () => {
988999
describe('legacy', () => {
9891000
describe('span profiling', () => {

0 commit comments

Comments
 (0)