-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add raw client error annotation and annotate GetFileContents #1570
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
8fc11ae
234565b
dd7f537
831b908
c12abc4
3727f68
2b7d781
8dad5c2
84b1f0c
349877f
0a6760d
16a1445
fe976d4
a1b6d7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,33 @@ func TestGitHubErrorContext(t *testing.T) { | |
| assert.Equal(t, "failed to execute mutation: GraphQL query failed", gqlError.Error()) | ||
| }) | ||
|
|
||
| t.Run("Raw API errors can be added to context and retrieved", func(t *testing.T) { | ||
| // Given a context with GitHub error tracking enabled | ||
| ctx := ContextWithGitHubErrors(context.Background()) | ||
|
|
||
| // Create a mock HTTP response | ||
| resp := &http.Response{ | ||
| StatusCode: 404, | ||
| Status: "404 Not Found", | ||
| } | ||
| originalErr := fmt.Errorf("raw content not found") | ||
|
|
||
| // When we add a raw API error to the context | ||
| rawAPIErr := newGitHubRawAPIError("failed to fetch raw content", resp, originalErr) | ||
| updatedCtx, err := addRawAPIErrorToContext(ctx, rawAPIErr) | ||
| require.NoError(t, err) | ||
|
|
||
| // Then we should be able to retrieve the error from the updated context | ||
| rawErrors, err := GetGitHubRawAPIErrors(updatedCtx) | ||
| require.NoError(t, err) | ||
| require.Len(t, rawErrors, 1) | ||
|
|
||
| rawError := rawErrors[0] | ||
| assert.Equal(t, "failed to fetch raw content", rawError.Message) | ||
| assert.Equal(t, resp, rawError.Response) | ||
| assert.Equal(t, originalErr, rawError.Err) | ||
|
Comment on lines
+87
to
+90
|
||
| }) | ||
|
|
||
| t.Run("multiple errors can be accumulated in context", func(t *testing.T) { | ||
| // Given a context with GitHub error tracking enabled | ||
| ctx := ContextWithGitHubErrors(context.Background()) | ||
|
|
@@ -82,6 +109,11 @@ func TestGitHubErrorContext(t *testing.T) { | |
| ctx, err = addGitHubGraphQLErrorToContext(ctx, gqlErr) | ||
| require.NoError(t, err) | ||
|
|
||
| // And add a raw API error | ||
| rawErr := newGitHubRawAPIError("raw error", &http.Response{StatusCode: 404}, fmt.Errorf("not found")) | ||
| ctx, err = addRawAPIErrorToContext(ctx, rawErr) | ||
| require.NoError(t, err) | ||
|
|
||
| // Then we should be able to retrieve all errors | ||
| apiErrors, err := GetGitHubAPIErrors(ctx) | ||
| require.NoError(t, err) | ||
|
|
@@ -91,10 +123,15 @@ func TestGitHubErrorContext(t *testing.T) { | |
| require.NoError(t, err) | ||
| assert.Len(t, gqlErrors, 1) | ||
|
|
||
| rawErrors, err := GetGitHubRawAPIErrors(ctx) | ||
| require.NoError(t, err) | ||
| assert.Len(t, rawErrors, 1) | ||
|
|
||
| // Verify error details | ||
| assert.Equal(t, "first error", apiErrors[0].Message) | ||
| assert.Equal(t, "second error", apiErrors[1].Message) | ||
| assert.Equal(t, "graphql error", gqlErrors[0].Message) | ||
| assert.Equal(t, "raw error", rawErrors[0].Message) | ||
| }) | ||
|
|
||
| t.Run("context pointer sharing allows middleware to inspect errors without context propagation", func(t *testing.T) { | ||
|
|
@@ -160,6 +197,12 @@ func TestGitHubErrorContext(t *testing.T) { | |
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), "context does not contain GitHubCtxErrors") | ||
| assert.Nil(t, gqlErrors) | ||
|
|
||
| // Same for raw API errors | ||
| rawErrors, err := GetGitHubRawAPIErrors(ctx) | ||
| assert.Error(t, err) | ||
| assert.Contains(t, err.Error(), "context does not contain GitHubCtxErrors") | ||
| assert.Nil(t, rawErrors) | ||
| }) | ||
|
|
||
| t.Run("ContextWithGitHubErrors resets existing errors", func(t *testing.T) { | ||
|
|
@@ -169,18 +212,31 @@ func TestGitHubErrorContext(t *testing.T) { | |
| ctx, err := NewGitHubAPIErrorToCtx(ctx, "existing error", resp, fmt.Errorf("error")) | ||
| require.NoError(t, err) | ||
|
|
||
| // Verify error exists | ||
| // Add a raw API error too | ||
| rawErr := newGitHubRawAPIError("existing raw error", &http.Response{StatusCode: 404}, fmt.Errorf("error")) | ||
| ctx, err = addRawAPIErrorToContext(ctx, rawErr) | ||
| require.NoError(t, err) | ||
|
|
||
| // Verify errors exist | ||
| apiErrors, err := GetGitHubAPIErrors(ctx) | ||
| require.NoError(t, err) | ||
| assert.Len(t, apiErrors, 1) | ||
|
|
||
| rawErrors, err := GetGitHubRawAPIErrors(ctx) | ||
| require.NoError(t, err) | ||
| assert.Len(t, rawErrors, 1) | ||
|
|
||
| // When we call ContextWithGitHubErrors again | ||
| resetCtx := ContextWithGitHubErrors(ctx) | ||
|
|
||
| // Then the errors should be cleared | ||
| // Then all errors should be cleared | ||
| apiErrors, err = GetGitHubAPIErrors(resetCtx) | ||
| require.NoError(t, err) | ||
| assert.Len(t, apiErrors, 0, "Errors should be reset") | ||
| assert.Len(t, apiErrors, 0, "API errors should be reset") | ||
|
|
||
| rawErrors, err = GetGitHubRawAPIErrors(resetCtx) | ||
| require.NoError(t, err) | ||
| assert.Len(t, rawErrors, 0, "Raw API errors should be reset") | ||
| }) | ||
|
|
||
| t.Run("NewGitHubAPIErrorResponse creates MCP error result and stores context error", func(t *testing.T) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.