MCPcopy
hub / github.com/github/github-mcp-server / ContextWithGitHubErrors

Function ContextWithGitHubErrors

pkg/errors/error.go:76–91  ·  view source on GitHub ↗

ContextWithGitHubErrors updates or creates a context with a pointer to GitHub error information (to be used by middleware).

(ctx context.Context)

Source from the content-addressed store, hash-verified

74
75// ContextWithGitHubErrors updates or creates a context with a pointer to GitHub error information (to be used by middleware).
76func ContextWithGitHubErrors(ctx context.Context) context.Context {
77 if ctx == nil {
78 ctx = context.Background()
79 }
80 if val, ok := ctx.Value(GitHubErrorKey{}).(*GitHubCtxErrors); ok {
81 // If the context already has GitHubCtxErrors, we just empty the slices to start fresh
82 val.api = []*GitHubAPIError{}
83 val.graphQL = []*GitHubGraphQLError{}
84 val.raw = []*GitHubRawAPIError{}
85 } else {
86 // If not, we create a new GitHubCtxErrors and set it in the context
87 ctx = context.WithValue(ctx, GitHubErrorKey{}, &GitHubCtxErrors{})
88 }
89
90 return ctx
91}
92
93// GetGitHubAPIErrors retrieves the slice of GitHubAPIErrors from the context.
94func GetGitHubAPIErrors(ctx context.Context) ([]*GitHubAPIError, error) {

Callers 4

RunStdioServerFunction · 0.92
TestGitHubErrorContextFunction · 0.85
TestMiddlewareScenarioFunction · 0.85

Calls

no outgoing calls

Tested by 3

TestGitHubErrorContextFunction · 0.68
TestMiddlewareScenarioFunction · 0.68