Skip to content

Commit 4b0d06f

Browse files
authored
test(google-cloud): Replace error handling using node domain (#14908)
1 parent c4cb57a commit 4b0d06f

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

packages/google-cloud-serverless/test/gcpfunction/cloud_event.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as domain from 'domain';
21
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
32

43
import { wrapCloudEventFunction } from '../../src/gcpfunction/cloud_events';
@@ -44,21 +43,21 @@ describe('wrapCloudEventFunction', () => {
4443

4544
function handleCloudEvent(fn: CloudEventFunctionWithCallback): Promise<any> {
4645
return new Promise((resolve, reject) => {
47-
// eslint-disable-next-line deprecation/deprecation
48-
const d = domain.create();
4946
const context = {
5047
type: 'event.type',
5148
};
52-
d.on('error', reject);
53-
d.run(() =>
54-
process.nextTick(fn, context, (err: any, result: any) => {
49+
50+
try {
51+
fn(context, (err: any, result: any) => {
5552
if (err != null || err != undefined) {
5653
reject(err);
5754
} else {
5855
resolve(result);
5956
}
60-
}),
61-
);
57+
});
58+
} catch (error) {
59+
reject(error);
60+
}
6261
});
6362
}
6463

packages/google-cloud-serverless/test/gcpfunction/events.test.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as domain from 'domain';
21
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
32

43
import type { Event } from '@sentry/core';
@@ -45,22 +44,18 @@ describe('wrapEventFunction', () => {
4544

4645
function handleEvent(fn: EventFunctionWithCallback): Promise<any> {
4746
return new Promise((resolve, reject) => {
48-
// eslint-disable-next-line deprecation/deprecation
49-
const d = domain.create();
5047
const context = {
5148
eventType: 'event.type',
5249
resource: 'some.resource',
5350
};
54-
d.on('error', reject);
55-
d.run(() =>
56-
process.nextTick(fn, {}, context, (err: any, result: any) => {
57-
if (err != null || err != undefined) {
58-
reject(err);
59-
} else {
60-
resolve(result);
61-
}
62-
}),
63-
);
51+
52+
fn({}, context, (err: any, result: any) => {
53+
if (err != null || err != undefined) {
54+
reject(err);
55+
} else {
56+
resolve(result);
57+
}
58+
});
6459
});
6560
}
6661

packages/google-cloud-serverless/test/gcpfunction/http.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as domain from 'domain';
2-
31
import type { Integration } from '@sentry/core';
42

53
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
@@ -58,17 +56,19 @@ describe('GCPFunction', () => {
5856
headers = { ...headers, ...trace_headers };
5957
}
6058
return new Promise((resolve, _reject) => {
61-
// eslint-disable-next-line deprecation/deprecation
62-
const d = domain.create();
6359
const req = {
6460
method: 'POST',
6561
url: '/path?q=query',
6662
headers: headers,
6763
body: { foo: 'bar' },
6864
} as Request;
6965
const res = { end: resolve } as Response;
70-
d.on('error', () => res.end());
71-
d.run(() => process.nextTick(fn, req, res));
66+
67+
try {
68+
fn(req, res);
69+
} catch (error) {
70+
res.end();
71+
}
7272
});
7373
}
7474

0 commit comments

Comments
 (0)