Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auto-edit): improve error logging #6609

Merged
merged 3 commits into from
Jan 14, 2025
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
39 changes: 39 additions & 0 deletions vscode/src/autoedits/autoedits-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as sentryCore from '@sentry/core'
import * as uuid from 'uuid'
import {
type MockInstance,
Expand Down Expand Up @@ -307,6 +308,44 @@ describe('AutoeditsProvider', () => {
expect(suggestedEventPayload.metadata.isRead).toBe(1)
})

it('errors are reported via telemetry recorded and Sentry', async () => {
const captureExceptionSpy = vi.spyOn(sentryCore, 'captureException')
const testError = new Error('test-error')

const { result } = await autoeditResultFor('const x = █', {
prediction: 'const x = 1\n',
getModelResponse() {
throw testError
},
})

expect(result).toBe(null)

// Error is captured by the telemetry recorded
expect(recordSpy).toHaveBeenCalledTimes(1)
expect(recordSpy).toHaveBeenNthCalledWith(1, 'cody.autoedit', 'error', expect.any(Object))

const errorPayload = recordSpy.mock.calls[0].at(2)
expect(errorPayload).toMatchInlineSnapshot(`
{
"metadata": {
"count": 1,
},
"privateMetadata": {
"message": "test-error",
"traceId": undefined,
},
"version": 0,
}
`)

// Error is captured by the Sentry service
expect(captureExceptionSpy).toHaveBeenCalledTimes(1)

const captureExceptionPayload = captureExceptionSpy.mock.calls[0].at(0)
expect(captureExceptionPayload).toEqual(testError)
})

it('rejects the current suggestion when the new one is shown', async () => {
const prediction = 'const x = 1\n'
const { provider } = await autoeditResultFor('const a = █\n', { prediction })
Expand Down
Loading
Loading