Skip to content

Commit b2ffa30

Browse files
AbhiPrasadclaude
andcommitted
fix: Replace deprecated url.parse with parseStringToURLObject
Node.js 24+ (Electron 40+) emits deprecation warnings for url.parse() which get captured by captureConsoleIntegration and cause test failures. Replace url.parse() calls in net-breadcrumbs.ts with parseStringToURLObject from @sentry/core which uses the WHATWG URL API. Also updates e2e test versions to include Electron 40.0.0. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4b89fab commit b2ffa30

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

src/main/integrations/net-breadcrumbs.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getBreadcrumbLogLevelFromHttpStatusCode,
88
getTraceData,
99
LRUMap,
10+
parseStringToURLObject,
1011
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
1112
SentryNonRecordingSpan,
1213
setHttpStatus,
@@ -15,7 +16,7 @@ import {
1516
} from '@sentry/core';
1617
import { logger } from '@sentry/node';
1718
import { ClientRequest, ClientRequestConstructorOptions, IncomingMessage, net as electronNet } from 'electron';
18-
import * as urlModule from 'url';
19+
import { format as urlFormat, UrlObject } from 'url';
1920

2021
type ShouldTraceFn = (method: string, url: string) => boolean;
2122

@@ -42,16 +43,23 @@ export interface NetOptions {
4243
* We want to match the final URL that Electron uses
4344
*/
4445
function parseOptions(optionsIn: ClientRequestConstructorOptions | string): { method: string; url: string } {
45-
const { method, options } =
46-
typeof optionsIn === 'string'
47-
? // eslint-disable-next-line deprecation/deprecation
48-
{ method: 'GET', options: urlModule.parse(optionsIn) }
49-
: { method: (optionsIn.method || 'GET').toUpperCase(), options: optionsIn };
46+
if (typeof optionsIn === 'string') {
47+
// For full URL strings, use the WHATWG URL API directly
48+
try {
49+
return { method: 'GET', url: new URL(optionsIn).href };
50+
} catch {
51+
// If URL parsing fails, return the original string
52+
return { method: 'GET', url: optionsIn };
53+
}
54+
}
55+
56+
const method = (optionsIn.method || 'GET').toUpperCase();
57+
const options = optionsIn;
5058

5159
let url = 'url' in options ? options.url : undefined;
5260

5361
if (!url) {
54-
const urlObj: urlModule.UrlObject = {};
62+
const urlObj: UrlObject = {};
5563
urlObj.protocol = options.protocol || 'http:';
5664

5765
if (options.host) {
@@ -68,12 +76,12 @@ function parseOptions(optionsIn: ClientRequestConstructorOptions | string): { me
6876
}
6977
}
7078

71-
// eslint-disable-next-line deprecation/deprecation
72-
const pathObj = urlModule.parse(options.path || '/');
73-
urlObj.pathname = pathObj.pathname;
74-
urlObj.search = pathObj.search;
75-
urlObj.hash = pathObj.hash;
76-
url = urlModule.format(urlObj);
79+
// Use parseStringToURLObject for path parsing (handles relative URLs)
80+
const pathObj = parseStringToURLObject(options.path || '/');
81+
urlObj.pathname = pathObj?.pathname;
82+
urlObj.search = pathObj?.search;
83+
urlObj.hash = pathObj?.hash;
84+
url = urlFormat(urlObj);
7785
}
7886

7987
return {

test/e2e/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["23.3.13","24.8.8","25.9.8","26.6.10","27.3.11","28.3.3","29.4.6","30.5.1","31.7.7","32.3.3","33.4.11","34.5.8","35.7.5","36.9.5","37.10.3","38.7.2","39.2.7"]
1+
["23.3.13","24.8.8","25.9.8","26.6.10","27.3.11","28.3.3","29.4.6","30.5.1","31.7.7","32.3.3","33.4.11","34.5.8","35.7.5","36.9.5","37.10.3","38.7.2","39.3.0","40.0.0"]

0 commit comments

Comments
 (0)