Skip to content

Commit d12e945

Browse files
chore: (studio) ensure to strip out paths from all data when reporting errors in studio (#32135)
* fix: (studio) ensure to strip out paths from all data when reporting errors in prompt and studio * disable with environment variable
1 parent e1ca574 commit d12e945

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

packages/server/lib/cloud/api/studio/report_studio_error.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export function reportStudioError ({
3636
}: ReportStudioErrorOptions): void {
3737
debug('Error reported:', error)
3838

39+
if (process.env.CYPRESS_CRASH_REPORTS === '0') {
40+
return
41+
}
42+
3943
// When developing locally, do not send to Sentry, but instead log to console.
4044
if (
4145
process.env.CYPRESS_LOCAL_STUDIO_PATH ||
@@ -77,7 +81,7 @@ export function reportStudioError ({
7781
stack: stripPath(errorObject.stack ?? `Unknown stack`),
7882
message: stripPath(errorObject.message ?? `Unknown message`),
7983
studioMethod,
80-
studioMethodArgs: studioMethodArgsString,
84+
studioMethodArgs: studioMethodArgsString ? stripPath(studioMethodArgsString) : undefined,
8185
}],
8286
}
8387

packages/server/test/unit/cloud/api/studio/report_studio_error_spec.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { reportStudioError } from '@packages/server/lib/cloud/api/studio/report_
55
describe('lib/cloud/api/studio/report_studio_error', () => {
66
let cloudRequestStub: sinon.SinonStub
77
let cloudApi: any
8+
let oldNodeEnv: string | undefined
89

910
beforeEach(() => {
11+
oldNodeEnv = process.env.NODE_ENV
1012
cloudRequestStub = sinon.stub()
1113
cloudApi = {
1214
cloudUrl: 'http://localhost:1234',
@@ -19,6 +21,14 @@ describe('lib/cloud/api/studio/report_studio_error', () => {
1921

2022
afterEach(() => {
2123
sinon.restore()
24+
delete process.env.CYPRESS_CRASH_REPORTS
25+
delete process.env.CYPRESS_LOCAL_STUDIO_PATH
26+
delete process.env.CYPRESS_INTERNAL_E2E_TESTING_SELF
27+
if (oldNodeEnv) {
28+
process.env.NODE_ENV = oldNodeEnv
29+
} else {
30+
delete process.env.NODE_ENV
31+
}
2232
})
2333

2434
describe('reportStudioError', () => {
@@ -82,6 +92,21 @@ describe('lib/cloud/api/studio/report_studio_error', () => {
8292
)
8393
})
8494

95+
it('does not report error when CYPRESS_CRASH_REPORTS is 0', () => {
96+
process.env.CYPRESS_CRASH_REPORTS = '0'
97+
const error = new Error('test error')
98+
99+
reportStudioError({
100+
cloudApi,
101+
studioHash: 'abc123',
102+
projectSlug: 'test-project',
103+
error,
104+
studioMethod: 'testMethod',
105+
})
106+
107+
expect(cloudRequestStub).to.not.have.been.called
108+
})
109+
85110
it('converts non-Error objects to Error', () => {
86111
const error = 'string error'
87112

@@ -152,7 +177,7 @@ describe('lib/cloud/api/studio/report_studio_error', () => {
152177

153178
it('includes studioMethodArgs when provided', () => {
154179
const error = new Error('test error')
155-
const args = ['arg1', { key: 'value' }]
180+
const args = ['arg1', { key: '/path/to/file.js' }]
156181

157182
reportStudioError({
158183
cloudApi,
@@ -173,7 +198,7 @@ describe('lib/cloud/api/studio/report_studio_error', () => {
173198
message: 'test error',
174199
stack: sinon.match((stack) => stack.includes('<stripped-path>report_studio_error_spec.ts')),
175200
studioMethod: 'testMethod',
176-
studioMethodArgs: JSON.stringify({ args }),
201+
studioMethodArgs: JSON.stringify({ args: ['arg1', { key: '<stripped-path>file.js' }] }),
177202
}],
178203
},
179204
{

0 commit comments

Comments
 (0)