Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/cli-kit/src/public/node/error-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ describe('skips sending errors to Bugsnag', () => {
expect(onNotify).not.toHaveBeenCalled()
expect(mockOutput.debug()).toMatch('Skipping Bugsnag report')
})

test('when error is expected', async () => {
const mockOutput = mockAndCaptureOutput()
const res = await sendErrorToBugsnag(new error.AbortError('In test'), 'expected_error')
expect(res.reported).toEqual(false)
expect(res.unhandled).toBeUndefined()
expect(onNotify).not.toHaveBeenCalled()
expect(mockOutput.debug()).toMatch('Skipping Bugsnag report for expected error')
})
})

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

test('processes AbortErrors as handled', async () => {
const res = await sendErrorToBugsnag(new error.AbortError('In test'), 'expected_error')
expect(res.reported).toEqual(true)
expect(res.unhandled).toEqual(false)
expect(onNotify).toHaveBeenCalledWith(res.error)
})

test.each([null, undefined, {}, {message: 'nope'}])('deals with strange things to throw %s', async (throwable) => {
const res = await sendErrorToBugsnag(throwable, 'unexpected_error')
expect(res.reported).toEqual(false)
Expand Down
5 changes: 5 additions & 0 deletions packages/cli-kit/src/public/node/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export async function sendErrorToBugsnag(
return {reported: false, error, unhandled: undefined}
}

if (exitMode === 'expected_error') {
outputDebug(`Skipping Bugsnag report for expected error`)
return {reported: false, error, unhandled: undefined}
}

// If the error was unexpected, we flag it as "unhandled" in Bugsnag. This is a helpful distinction.
const unhandled = exitMode === 'unexpected_error'

Expand Down
Loading