From e5c096b80bf685946cbfb955ff030a7e91ad8f12 Mon Sep 17 00:00:00 2001 From: GrizliK1988 Date: Sat, 4 Jan 2025 14:43:48 +0100 Subject: [PATCH 1/3] test(google-cloud): Replace error handling using node domain (#14769) Replace error handling using deprecated node:domain in google-cloud-serverless tests Fixes #14769 --- .../test/gcpfunction/cloud_event.test.ts | 15 ++++++------ .../test/gcpfunction/events.test.ts | 23 ++++++++----------- .../test/gcpfunction/http.test.ts | 12 +++++----- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/packages/google-cloud-serverless/test/gcpfunction/cloud_event.test.ts b/packages/google-cloud-serverless/test/gcpfunction/cloud_event.test.ts index 95323881828d..8bbc926643f7 100644 --- a/packages/google-cloud-serverless/test/gcpfunction/cloud_event.test.ts +++ b/packages/google-cloud-serverless/test/gcpfunction/cloud_event.test.ts @@ -1,4 +1,3 @@ -import * as domain from 'domain'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import { wrapCloudEventFunction } from '../../src/gcpfunction/cloud_events'; @@ -44,21 +43,21 @@ describe('wrapCloudEventFunction', () => { function handleCloudEvent(fn: CloudEventFunctionWithCallback): Promise { return new Promise((resolve, reject) => { - // eslint-disable-next-line deprecation/deprecation - const d = domain.create(); const context = { type: 'event.type', }; - d.on('error', reject); - d.run(() => - process.nextTick(fn, context, (err: any, result: any) => { + + try { + fn(context, (err: any, result: any) => { if (err != null || err != undefined) { reject(err); } else { resolve(result); } - }), - ); + }); + } catch (error) { + reject(error); + } }); } diff --git a/packages/google-cloud-serverless/test/gcpfunction/events.test.ts b/packages/google-cloud-serverless/test/gcpfunction/events.test.ts index aa449f5407c9..c58db5b1176b 100644 --- a/packages/google-cloud-serverless/test/gcpfunction/events.test.ts +++ b/packages/google-cloud-serverless/test/gcpfunction/events.test.ts @@ -1,4 +1,3 @@ -import * as domain from 'domain'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import type { Event } from '@sentry/core'; @@ -45,22 +44,20 @@ describe('wrapEventFunction', () => { function handleEvent(fn: EventFunctionWithCallback): Promise { return new Promise((resolve, reject) => { - // eslint-disable-next-line deprecation/deprecation - const d = domain.create(); const context = { eventType: 'event.type', resource: 'some.resource', }; - d.on('error', reject); - d.run(() => - process.nextTick(fn, {}, context, (err: any, result: any) => { - if (err != null || err != undefined) { - reject(err); - } else { - resolve(result); - } - }), - ); + + const result = fn({}, context, (err: any, result: any) => { + if (err != null || err != undefined) { + reject(err); + } else { + resolve(result); + } + }); + + Promise.allSettled([result]).catch(error => reject(error)); }); } diff --git a/packages/google-cloud-serverless/test/gcpfunction/http.test.ts b/packages/google-cloud-serverless/test/gcpfunction/http.test.ts index 08d53df50b31..7f456237ad9c 100644 --- a/packages/google-cloud-serverless/test/gcpfunction/http.test.ts +++ b/packages/google-cloud-serverless/test/gcpfunction/http.test.ts @@ -1,5 +1,3 @@ -import * as domain from 'domain'; - import type { Integration } from '@sentry/core'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; @@ -58,8 +56,6 @@ describe('GCPFunction', () => { headers = { ...headers, ...trace_headers }; } return new Promise((resolve, _reject) => { - // eslint-disable-next-line deprecation/deprecation - const d = domain.create(); const req = { method: 'POST', url: '/path?q=query', @@ -67,8 +63,12 @@ describe('GCPFunction', () => { body: { foo: 'bar' }, } as Request; const res = { end: resolve } as Response; - d.on('error', () => res.end()); - d.run(() => process.nextTick(fn, req, res)); + + try { + fn(req, res); + } catch (error) { + res.end(); + } }); } From 678faaa09016db80a7f85ec8c0a26ee4b66b3588 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Mon, 13 Jan 2025 13:59:58 +0000 Subject: [PATCH 2/3] simplify --- .../google-cloud-serverless/test/gcpfunction/events.test.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/google-cloud-serverless/test/gcpfunction/events.test.ts b/packages/google-cloud-serverless/test/gcpfunction/events.test.ts index c58db5b1176b..f4c92d5c48f4 100644 --- a/packages/google-cloud-serverless/test/gcpfunction/events.test.ts +++ b/packages/google-cloud-serverless/test/gcpfunction/events.test.ts @@ -1,4 +1,4 @@ -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isThenable } from '@sentry/core'; import type { Event } from '@sentry/core'; import { wrapEventFunction } from '../../src/gcpfunction/events'; @@ -49,15 +49,13 @@ describe('wrapEventFunction', () => { resource: 'some.resource', }; - const result = fn({}, context, (err: any, result: any) => { + fn({}, context, (err: any, result: any) => { if (err != null || err != undefined) { reject(err); } else { resolve(result); } }); - - Promise.allSettled([result]).catch(error => reject(error)); }); } From 5ad4679a94d525e0bb4a17f2cab4af059dcde75a Mon Sep 17 00:00:00 2001 From: GrizliK1988 Date: Wed, 15 Jan 2025 08:13:23 +0100 Subject: [PATCH 3/3] fix biome warning --- .../google-cloud-serverless/test/gcpfunction/events.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/google-cloud-serverless/test/gcpfunction/events.test.ts b/packages/google-cloud-serverless/test/gcpfunction/events.test.ts index f4c92d5c48f4..aad3d5ec1645 100644 --- a/packages/google-cloud-serverless/test/gcpfunction/events.test.ts +++ b/packages/google-cloud-serverless/test/gcpfunction/events.test.ts @@ -1,4 +1,4 @@ -import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isThenable } from '@sentry/core'; +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core'; import type { Event } from '@sentry/core'; import { wrapEventFunction } from '../../src/gcpfunction/events';