github/github-mcp-server · warning
failed to marshal discussion categories: %w
Error message
failed to marshal discussion categories: %w
What it means
list_discussion_categories marshals a response map of the categories slice, pageInfo (bools and cursor strings), and totalCount int after a successful GraphQL query. All values are primitives derived from GraphQL scalars, so json.Marshal's failure modes (unsupported types, cycles, NaN) are not reachable; the branch guards against future type regressions in the response construction.
Source
Thrown at pkg/github/discussions.go:1098
"name": string(c.Name),
})
}
// Create response with pagination info
response := map[string]any{
"categories": categories,
"pageInfo": map[string]any{
"hasNextPage": q.Repository.DiscussionCategories.PageInfo.HasNextPage,
"hasPreviousPage": q.Repository.DiscussionCategories.PageInfo.HasPreviousPage,
"startCursor": string(q.Repository.DiscussionCategories.PageInfo.StartCursor),
"endCursor": string(q.Repository.DiscussionCategories.PageInfo.EndCursor),
},
"totalCount": q.Repository.DiscussionCategories.TotalCount,
}
out, err := json.Marshal(response)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal discussion categories: %w", err)
}
result := utils.NewToolResultText(string(out))
// Discussion categories are repo-defined structural metadata
// (trusted); confidentiality follows repo visibility.
result = attachRepoVisibilityIFCLabelLazy(ctx, deps, owner, repo, result, ifc.LabelRepoMetadata)
return result, nil, nil
},
)
}
View on GitHub (pinned to 0ea1f775a7)
Solutions
- Project categories into maps of string/int before insertion into the response
- Add a golden-file test for the categories response JSON
- On occurrence, inspect element types of the categories slice — the defect is in this handler's projection, not the API call
- Do not retry the tool: the query already succeeded and marshal outcome is deterministic per input
Defensive patterns
Strategy: try-catch
Try / catch
out, err := json.Marshal(response)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal discussion categories: %w", err)
} Prevention
- Project category objects into plain maps (id, name strings)
- Golden-test the categories response JSON
- Do not retry on marshal errors — the query already succeeded and the outcome is deterministic
When it happens
Trigger: A refactor moving raw githubv4 category objects into the categories slice without projecting to plain maps; addition of float fields that could be NaN; cyclic structures from embedding. Current GitHub category data (ids, names, cursors) cannot trip it.
Common situations: Forks adding category description/emoji fields as typed objects; library upgrades changing embedded struct shapes; test doubles with unmarshalable fields.
Related errors
- failed to marshal discussions: %w
- failed to marshal discussion: %w
- failed to marshal comments: %w
- failed to marshal comment: %w
- failed to marshal response: %w
AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15).
Data as JSON: /api/errors/a090eb4fa7c5a2d4.
Report an issue: GitHub.