Skip to content

Commit d8c4733

Browse files
authored
fix: set root for RewriteFrames integration (#650)
1 parent 5570a7f commit d8c4733

File tree

8 files changed

+51
-13
lines changed

8 files changed

+51
-13
lines changed

Diff for: docs/content/en/configuration/options.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ sentry: {
220220
{
221221
ExtraErrorData: {},
222222
ReportingObserver: { types: ['crash'] },
223-
RewriteFrames: {},
224223
}
225224
```
226225
- Sentry by default also enables the following browser integrations: `Breadcrumbs`, `Dedupe`, `FunctionToString`, `GlobalHandlers`, `HttpContext`, `InboundFilters`, `LinkedErrors`, `TryCatch`.
@@ -243,7 +242,7 @@ sentry: {
243242
{
244243
Dedupe: {},
245244
ExtraErrorData: {},
246-
RewriteFrames: {},
245+
RewriteFrames: { root: <rootDir> },
247246
Transaction: {},
248247
}
249248
```

Diff for: src/module.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ export default defineNuxtModule<ModuleConfiguration>({
3838
clientIntegrations: {
3939
ExtraErrorData: {},
4040
ReportingObserver: { types: ['crash'] },
41-
RewriteFrames: {},
4241
},
4342
serverIntegrations: {
4443
Dedupe: {},
4544
ExtraErrorData: {},
46-
RewriteFrames: {},
45+
RewriteFrames: { root: nuxt.options.rootDir },
4746
Transaction: {},
4847
},
4948
customClientIntegrations: '',

Diff for: test/fixture/typescript/api/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { ServerMiddleware } from '@nuxt/types'
2+
3+
export default <ServerMiddleware> function serverRoute (req, res, next) {
4+
// @ts-expect-error crash on purpose
5+
apiCrash()
6+
res.end('OK')
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Context } from '@nuxt/types'
2-
import type { ModuleOptions } from 'src/types'
32

4-
export default function (_context: Context): ModuleOptions['clientIntegrations'] {
5-
return {}
3+
export default function (_context: Context): unknown[] {
4+
return []
65
}

Diff for: test/fixture/typescript/nuxt.config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const config: NuxtConfig = {
1919
modules: [
2020
jiti.resolve('../../..'),
2121
],
22+
publicRuntimeConfig: {
23+
baseURL: 'http://localhost:3000',
24+
},
2225
sentry: {
2326
dsn: 'https://fe8b7df6ea7042f69d7a97c66c2934f7@sentry.io.nuxt/1429779',
2427
clientIntegrations: {
@@ -38,6 +41,9 @@ const config: NuxtConfig = {
3841
serverConfig: '~/config/server.config',
3942
tracing: true,
4043
},
44+
serverMiddleware: [
45+
{ path: '/api', handler: '~/api/index' },
46+
],
4147
typescript: {
4248
typeCheck: false,
4349
},

Diff for: test/fixture/typescript/pages/index.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
import { defineComponent } from 'vue'
1717
1818
export default defineComponent({
19-
asyncData ({ $sentry, query }) {
19+
async asyncData ({ $sentry, $config, query }) {
2020
if (query.crashOnLoad) {
2121
// @ts-ignore forces a crash
2222
// eslint-disable-next-line no-undef
2323
crashOnLoad()
24+
} else if (query.crashOnLoadInApi) {
25+
// Request crashes but doesn't propagate to asyncData.
26+
await fetch(`${$config.baseURL}/api`)
2427
}
2528
2629
if (process.server) {

Diff for: test/options.test.ts

-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ describe('Resolve Client Options', () => {
3535
integrations: {
3636
ExtraErrorData: {},
3737
ReportingObserver: {},
38-
RewriteFrames: {},
3938
},
4039
lazy: false,
4140
logMockCalls: true,
@@ -72,7 +71,6 @@ describe('Resolve Client Options', () => {
7271
integrations: {
7372
ExtraErrorData: {},
7473
ReportingObserver: {},
75-
RewriteFrames: {},
7674
},
7775
lazy: false,
7876
logMockCalls: true,

Diff for: test/typescript.test.ts

+30-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { dirname } from 'path'
44
import { describe, afterAll, beforeAll, beforeEach, test, expect } from 'vitest'
55
import type { Browser } from 'playwright-chromium'
66
import sentryTestkit from 'sentry-testkit'
7-
import { setup, url } from '@nuxtjs/module-test-utils'
7+
// TODO: Until sentry-kit types are fixed
8+
import type { Stacktrace } from '@sentry/node'
9+
import type { NuxtConfig } from '@nuxt/types'
10+
import { generatePort, setup, url } from '@nuxtjs/module-test-utils'
811
import type { Nuxt } from '../src/kit-shim'
912
import { $$, createBrowser, loadConfig } from './utils'
1013

@@ -20,8 +23,15 @@ describe('Smoke test (typescript)', () => {
2023

2124
beforeAll(async () => {
2225
await localServer.start(TEST_DSN)
23-
const dsn = localServer.getDsn()
24-
nuxt = (await setup(loadConfig(__dirname, 'typescript', { sentry: { dsn } }, { merge: true }))).nuxt
26+
const dsn = localServer.getDsn()!
27+
const port = await generatePort()
28+
const overrides: NuxtConfig = {
29+
sentry: { dsn },
30+
server: { port },
31+
publicRuntimeConfig: { baseURL: url('') },
32+
}
33+
const config = loadConfig(__dirname, 'typescript', overrides, { merge: true })
34+
nuxt = (await setup(config)).nuxt
2535
browser = await createBrowser()
2636
})
2737

@@ -64,6 +74,23 @@ describe('Smoke test (typescript)', () => {
6474
expect(reports[0].extra!.foo).toBe('1')
6575
})
6676

77+
test('catches a server crash in server middleware', async () => {
78+
const page = await browser.newPage()
79+
const response = await page.goto(url('/?crashOnLoadInApi=1'))
80+
expect(response!.status()).toBe(200)
81+
82+
const reports = testkit.reports()
83+
expect(reports).toHaveLength(1)
84+
expect(reports[0].error?.message).toContain('apiCrash is not defined')
85+
expect(reports[0].error?.stacktrace as Stacktrace).toMatchObject({
86+
frames: expect.arrayContaining([
87+
expect.objectContaining({
88+
filename: 'app:///api/index.ts',
89+
}),
90+
]),
91+
})
92+
})
93+
6794
test('catches a client crash', async () => {
6895
const page = await browser.newPage()
6996
await page.goto(url('/'))

0 commit comments

Comments
 (0)