Skip to content

Commit a9cbe62

Browse files
Merge pull request #7316 from Shopify/rp/skip-bugsnag-expected-errors
fix: stop reporting expected function errors
2 parents be8170c + 39c7b05 commit a9cbe62

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

packages/cli-kit/src/public/node/error-handler.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ describe('skips sending errors to Bugsnag', () => {
174174
expect(onNotify).not.toHaveBeenCalled()
175175
expect(mockOutput.debug()).toMatch('Skipping Bugsnag report')
176176
})
177+
178+
test('when error is expected', async () => {
179+
const mockOutput = mockAndCaptureOutput()
180+
const res = await sendErrorToBugsnag(new error.AbortError('In test'), 'expected_error')
181+
expect(res.reported).toEqual(false)
182+
expect(res.unhandled).toBeUndefined()
183+
expect(onNotify).not.toHaveBeenCalled()
184+
expect(mockOutput.debug()).toMatch('Skipping Bugsnag report for expected error')
185+
})
177186
})
178187

179188
describe('sends errors to Bugsnag', () => {
@@ -200,13 +209,6 @@ describe('sends errors to Bugsnag', () => {
200209
expect(onNotify).toHaveBeenCalledWith(res.error)
201210
})
202211

203-
test('processes AbortErrors as handled', async () => {
204-
const res = await sendErrorToBugsnag(new error.AbortError('In test'), 'expected_error')
205-
expect(res.reported).toEqual(true)
206-
expect(res.unhandled).toEqual(false)
207-
expect(onNotify).toHaveBeenCalledWith(res.error)
208-
})
209-
210212
test.each([null, undefined, {}, {message: 'nope'}])('deals with strange things to throw %s', async (throwable) => {
211213
const res = await sendErrorToBugsnag(throwable, 'unexpected_error')
212214
expect(res.reported).toEqual(false)

packages/cli-kit/src/public/node/error-handler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export async function sendErrorToBugsnag(
7676
return {reported: false, error, unhandled: undefined}
7777
}
7878

79+
if (exitMode === 'expected_error') {
80+
outputDebug(`Skipping Bugsnag report for expected error`)
81+
return {reported: false, error, unhandled: undefined}
82+
}
83+
7984
// If the error was unexpected, we flag it as "unhandled" in Bugsnag. This is a helpful distinction.
8085
const unhandled = exitMode === 'unexpected_error'
8186

0 commit comments

Comments
 (0)