{"record":{"id":"3a5568b731ca702d","repo":"github/github-mcp-server","slug":"failed-to-marshal-discussions-w","errorCode":null,"errorMessage":"failed to marshal discussions: %w","messagePattern":"failed to marshal discussions: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/github/discussions.go","lineNumber":274,"sourceCode":"\t\t\t\tpageInfo = fragment.PageInfo\n\t\t\t\ttotalCount = fragment.TotalCount\n\t\t\t}\n\n\t\t\t// Create response with pagination info\n\t\t\tresponse := map[string]any{\n\t\t\t\t\"discussions\": discussions,\n\t\t\t\t\"pageInfo\": map[string]any{\n\t\t\t\t\t\"hasNextPage\":     pageInfo.HasNextPage,\n\t\t\t\t\t\"hasPreviousPage\": pageInfo.HasPreviousPage,\n\t\t\t\t\t\"startCursor\":     string(pageInfo.StartCursor),\n\t\t\t\t\t\"endCursor\":       string(pageInfo.EndCursor),\n\t\t\t\t},\n\t\t\t\t\"totalCount\": totalCount,\n\t\t\t}\n\n\t\t\tout, err := json.Marshal(response)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to marshal discussions: %w\", err)\n\t\t\t}\n\t\t\tresult := utils.NewToolResultText(string(out))\n\t\t\t// Discussion content is user-authored (untrusted); confidentiality\n\t\t\t// follows repo visibility.\n\t\t\tresult = attachRepoVisibilityIFCLabelLazy(ctx, deps, owner, repo, result, ifc.LabelRepoUserContent)\n\t\t\treturn result, nil, nil\n\t\t},\n\t)\n}\n\nfunc GetDiscussion(t translations.TranslationHelperFunc) inventory.ServerTool {\n\treturn NewTool(\n\t\tToolsetMetadataDiscussions,\n\t\tmcp.Tool{\n\t\t\tName:        \"get_discussion\",\n\t\t\tDescription: t(\"TOOL_GET_DISCUSSION_DESCRIPTION\", \"Get a specific discussion by ID\"),\n\t\t\tAnnotations: &mcp.ToolAnnotations{\n\t\t\t\tTitle:        t(\"TOOL_GET_DISCUSSION_USER_TITLE\", \"Get discussion\"),","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/discussions.go#L256-L292","documentation":"After the list_discussions GraphQL query succeeds, the handler assembles a response map (discussions slice, pageInfo strings/bools, totalCount int) and json.Marshals it. json.Marshal only errors on unsupported values (channels, functions, complex numbers, NaN/Inf floats) or cyclic references; every field here is a plain string/bool/int derived from GraphQL scalars, so this path is defensive and effectively unreachable in practice. If it ever fires, a schema/type change introduced an unmarshalable value.","triggerScenarios":"A future change storing a githubv4.ID, time.Time with a bad MarshalJSON, or a func/channel inside the discussions slice or pageInfo map; cyclic structures if discussion objects ever reference each other. Not triggerable by any GitHub API response with the current types.","commonSituations":"Refactors that swap plain strings for typed wrappers with custom marshaling bugs; test code mutating the response shape; library forks adding fields. Real GitHub data (titles, cursors, counts) cannot cause it.","solutions":["Treat a hit as a code defect: inspect the discussions slice's element types for funcs, channels, or custom MarshalJSON implementations","Add a unit test that marshals a representative response map to catch type regressions in CI","Keep the response composed of primitives (string/int/bool) as it is today","If hit in production, log the payload types (not contents) and fall back to a minimal shape so the tool still returns something useful"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := json.Marshal(response)\nif err != nil {\n\t// defensive branch: a failure means a code defect in response construction\n\tlogger.Error(\"marshal discussions failed\", \"err\", err)\n\treturn nil, nil, fmt.Errorf(\"failed to marshal discussions: %w\", err)\n}","preventionTips":["Keep response maps composed of string/int/bool primitives","Convert GraphQL scalars (githubv4.ID, githubv4.URI) to strings before insertion","Add golden JSON tests per tool response shape to catch type regressions in CI"],"tags":["go","json-marshal","defensive-code","discussions"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}