Skip to content

Commit e517526

Browse files
author
Luca Forstner
committed
Merge remote-tracking branch 'origin/develop' into lforst-sync-gitflow
2 parents 7ef6da3 + 7093d92 commit e517526

File tree

68 files changed

+1646
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1646
-88
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ jobs:
977977
with:
978978
path: ${{ github.workspace }}/packages/*/*.tgz
979979
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
980+
fail-on-cache-miss: true
980981

981982
- name: Install Playwright
982983
uses: ./.github/actions/install-playwright
@@ -1076,6 +1077,7 @@ jobs:
10761077
with:
10771078
path: ${{ github.workspace }}/packages/*/*.tgz
10781079
key: ${{ env.BUILD_CACHE_TARBALL_KEY }}
1080+
fail-on-cache-miss: true
10791081

10801082
- name: Install Playwright
10811083
uses: ./.github/actions/install-playwright
@@ -1446,6 +1448,7 @@ jobs:
14461448
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
14471449
key: ${{ needs.job_build.outputs.dependency_cache_key }}
14481450
enableCrossOsArchive: true
1451+
fail-on-cache-miss: true
14491452

14501453
- name: Restore build cache
14511454
uses: actions/cache/restore@v4
@@ -1454,6 +1457,7 @@ jobs:
14541457
path: ${{ env.CACHED_BUILD_PATHS }}
14551458
key: ${{ needs.job_build.outputs.dependency_cache_key }}
14561459
enableCrossOsArchive: true
1460+
fail-on-cache-miss: true
14571461

14581462
- name: Configure safe directory
14591463
run: |
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Automation: Cleanup PR caches"
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
7+
jobs:
8+
cleanup:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
# `actions:write` permission is required to delete caches
12+
# See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
13+
actions: write
14+
contents: read
15+
steps:
16+
- name: Check out code
17+
uses: actions/checkout@v4
18+
19+
- name: Cleanup
20+
run: |
21+
gh extension install actions/gh-actions-cache
22+
23+
REPO=${{ github.repository }}
24+
BRANCH=refs/pull/${{ github.event.pull_request.number }}/merge
25+
26+
echo "Fetching list of cache key"
27+
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
28+
29+
## Setting this to not fail the workflow while deleting cache keys.
30+
set +e
31+
echo "Deleting caches..."
32+
for cacheKey in $cacheKeysForPR
33+
do
34+
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
35+
done
36+
echo "Done"
37+
env:
38+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242
"[typescript]": {
4343
"editor.defaultFormatter": "biomejs.biome"
4444
},
45-
"cSpell.words": ["arrayify"]
45+
"cSpell.words": ["arrayify", "OTEL"]
4646
}

dev-packages/e2e-tests/test-applications/nestjs-basic/src/app.controller.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { Controller, Get, Param, ParseIntPipe, UseGuards, UseInterceptors } from '@nestjs/common';
1+
import { Controller, Get, Param, ParseIntPipe, UseFilters, UseGuards, UseInterceptors } from '@nestjs/common';
22
import { flush } from '@sentry/nestjs';
33
import { AppService } from './app.service';
4+
import { ExampleExceptionGlobalFilter } from './example-global-filter.exception';
5+
import { ExampleExceptionLocalFilter } from './example-local-filter.exception';
6+
import { ExampleLocalFilter } from './example-local.filter';
47
import { ExampleGuard } from './example.guard';
58
import { ExampleInterceptor } from './example.interceptor';
69

710
@Controller()
11+
@UseFilters(ExampleLocalFilter)
812
export class AppController {
913
constructor(private readonly appService: AppService) {}
1014

@@ -74,4 +78,14 @@ export class AppController {
7478
async flush() {
7579
await flush();
7680
}
81+
82+
@Get('example-exception-global-filter')
83+
async exampleExceptionGlobalFilter() {
84+
throw new ExampleExceptionGlobalFilter();
85+
}
86+
87+
@Get('example-exception-local-filter')
88+
async exampleExceptionLocalFilter() {
89+
throw new ExampleExceptionLocalFilter();
90+
}
7791
}

dev-packages/e2e-tests/test-applications/nestjs-basic/src/app.module.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
import { MiddlewareConsumer, Module } from '@nestjs/common';
2+
import { APP_FILTER } from '@nestjs/core';
23
import { ScheduleModule } from '@nestjs/schedule';
3-
import { SentryModule } from '@sentry/nestjs/setup';
4+
import { SentryGlobalFilter, SentryModule } from '@sentry/nestjs/setup';
45
import { AppController } from './app.controller';
56
import { AppService } from './app.service';
7+
import { ExampleGlobalFilter } from './example-global.filter';
68
import { ExampleMiddleware } from './example.middleware';
79

810
@Module({
911
imports: [SentryModule.forRoot(), ScheduleModule.forRoot()],
1012
controllers: [AppController],
11-
providers: [AppService],
13+
providers: [
14+
AppService,
15+
{
16+
provide: APP_FILTER,
17+
useClass: SentryGlobalFilter,
18+
},
19+
{
20+
provide: APP_FILTER,
21+
useClass: ExampleGlobalFilter,
22+
},
23+
],
1224
})
1325
export class AppModule {
1426
configure(consumer: MiddlewareConsumer): void {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export class ExampleExceptionGlobalFilter extends Error {
2+
constructor() {
3+
super('Original global example exception!');
4+
}
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ArgumentsHost, BadRequestException, Catch, ExceptionFilter } from '@nestjs/common';
2+
import { Request, Response } from 'express';
3+
import { ExampleExceptionGlobalFilter } from './example-global-filter.exception';
4+
5+
@Catch(ExampleExceptionGlobalFilter)
6+
export class ExampleGlobalFilter implements ExceptionFilter {
7+
catch(exception: BadRequestException, host: ArgumentsHost): void {
8+
const ctx = host.switchToHttp();
9+
const response = ctx.getResponse<Response>();
10+
const request = ctx.getRequest<Request>();
11+
12+
response.status(400).json({
13+
statusCode: 400,
14+
timestamp: new Date().toISOString(),
15+
path: request.url,
16+
message: 'Example exception was handled by global filter!',
17+
});
18+
}
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export class ExampleExceptionLocalFilter extends Error {
2+
constructor() {
3+
super('Original local example exception!');
4+
}
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ArgumentsHost, BadRequestException, Catch, ExceptionFilter } from '@nestjs/common';
2+
import { Request, Response } from 'express';
3+
import { ExampleExceptionLocalFilter } from './example-local-filter.exception';
4+
5+
@Catch(ExampleExceptionLocalFilter)
6+
export class ExampleLocalFilter implements ExceptionFilter {
7+
catch(exception: BadRequestException, host: ArgumentsHost): void {
8+
const ctx = host.switchToHttp();
9+
const response = ctx.getResponse<Response>();
10+
const request = ctx.getRequest<Request>();
11+
12+
response.status(400).json({
13+
statusCode: 400,
14+
timestamp: new Date().toISOString(),
15+
path: request.url,
16+
message: 'Example exception was handled by local filter!',
17+
});
18+
}
19+
}

dev-packages/e2e-tests/test-applications/nestjs-basic/tests/errors.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,73 @@ test('Does not send RpcExceptions to Sentry', async ({ baseURL }) => {
9494

9595
expect(errorEventOccurred).toBe(false);
9696
});
97+
98+
test('Global exception filter registered in main module is applied and exception is not sent to Sentry', async ({
99+
baseURL,
100+
}) => {
101+
let errorEventOccurred = false;
102+
103+
waitForError('nestjs-basic', event => {
104+
if (!event.type && event.exception?.values?.[0]?.value === 'Example exception was handled by global filter!') {
105+
errorEventOccurred = true;
106+
}
107+
108+
return event?.transaction === 'GET /example-exception-global-filter';
109+
});
110+
111+
const transactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
112+
return transactionEvent?.transaction === 'GET /example-exception-global-filter';
113+
});
114+
115+
const response = await fetch(`${baseURL}/example-exception-global-filter`);
116+
const responseBody = await response.json();
117+
118+
expect(response.status).toBe(400);
119+
expect(responseBody).toEqual({
120+
statusCode: 400,
121+
timestamp: expect.any(String),
122+
path: '/example-exception-global-filter',
123+
message: 'Example exception was handled by global filter!',
124+
});
125+
126+
await transactionEventPromise;
127+
128+
(await fetch(`${baseURL}/flush`)).text();
129+
130+
expect(errorEventOccurred).toBe(false);
131+
});
132+
133+
test('Local exception filter registered in main module is applied and exception is not sent to Sentry', async ({
134+
baseURL,
135+
}) => {
136+
let errorEventOccurred = false;
137+
138+
waitForError('nestjs-basic', event => {
139+
if (!event.type && event.exception?.values?.[0]?.value === 'Example exception was handled by local filter!') {
140+
errorEventOccurred = true;
141+
}
142+
143+
return event?.transaction === 'GET /example-exception-local-filter';
144+
});
145+
146+
const transactionEventPromise = waitForTransaction('nestjs-basic', transactionEvent => {
147+
return transactionEvent?.transaction === 'GET /example-exception-local-filter';
148+
});
149+
150+
const response = await fetch(`${baseURL}/example-exception-local-filter`);
151+
const responseBody = await response.json();
152+
153+
expect(response.status).toBe(400);
154+
expect(responseBody).toEqual({
155+
statusCode: 400,
156+
timestamp: expect.any(String),
157+
path: '/example-exception-local-filter',
158+
message: 'Example exception was handled by local filter!',
159+
});
160+
161+
await transactionEventPromise;
162+
163+
(await fetch(`${baseURL}/flush`)).text();
164+
165+
expect(errorEventOccurred).toBe(false);
166+
});

0 commit comments

Comments
 (0)