{"record":{"id":"21a78b2fb8d2460b","repo":"github/github-mcp-server","slug":"failed-to-marshal-comments-w","errorCode":null,"errorMessage":"failed to marshal comments: %w","messagePattern":"failed to marshal comments: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/github/discussions.go","lineNumber":589,"sourceCode":"\t\t\t\tpageInfo = q.Repository.Discussion.Comments.PageInfo\n\t\t\t\ttotalCount = q.Repository.Discussion.Comments.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\"comments\": comments,\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 comments: %w\", err)\n\t\t\t}\n\n\t\t\tresult := utils.NewToolResultText(string(out))\n\t\t\t// Discussion comments are user-authored (untrusted); confidentiality\n\t\t\t// follows repo visibility.\n\t\t\tresult = attachRepoVisibilityIFCLabelLazy(ctx, deps, params.Owner, params.Repo, result, ifc.LabelRepoUserContent)\n\t\t\treturn result, nil, nil\n\t\t},\n\t)\n}\n\nfunc DiscussionCommentWrite(t translations.TranslationHelperFunc) inventory.ServerTool {\n\treturn NewTool(\n\t\tToolsetMetadataDiscussions,\n\t\tmcp.Tool{\n\t\t\tName: \"discussion_comment_write\",\n\t\t\tDescription: t(\"TOOL_DISCUSSION_COMMENT_WRITE_DESCRIPTION\", `Write operations for discussion comments.\nSupports adding top-level comments, replying to existing comments, updating comment content, deleting comments, and marking or unmarking comments as the answer.`),","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/discussions.go#L571-L607","documentation":"list_discussion_comments builds a response map (comments slice, pageInfo, totalCount) and json.Marshals it after a successful query. Identical defensive pattern to the other discussions list endpoints: all constituent values are primitives from GraphQL scalars, and json.Marshal's only error conditions (unsupported types, cycles, NaN) cannot arise from them. Encountering it means the response composition code changed to include something unmarshalable.","triggerScenarios":"A refactor embedding raw githubv4 structs (which may carry func fields or unusual types) instead of projected plain values; NaN/Inf if numeric float fields are ever added; cyclic comment/reaction graphs. Not producible by GitHub data through the current code.","commonSituations":"Extending the comment payload with reaction or author objects by direct struct inclusion; version upgrades changing embedded types; test harnesses substituting fake comment objects with unmarshalable fields.","solutions":["Project every nested GraphQL object into maps of primitives before insertion, as the current code does","Write a table-driven marshal test covering comments with and without optional fields","On occurrence, diff the response construction block; the defect is local to this handler","Guard tool availability: since the query already succeeded, retrying the tool will not change the marshal outcome; fix code instead"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := json.Marshal(response)\nif err != nil {\n\treturn nil, nil, fmt.Errorf(\"failed to marshal comments: %w\", err)\n}","preventionTips":["Project nested GraphQL objects (authors, reactions) into plain maps before response assembly","Avoid embedding githubv4 structs wholesale","Table-test marshaling for comments with/without optional fields"],"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"}