{"record":{"id":"09f3b2307ea5fd56","repo":"github/github-mcp-server","slug":"failed-to-marshal-response-w-09f3b2","errorCode":null,"errorMessage":"failed to marshal response: %w","messagePattern":"failed to marshal response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/github/repositories.go","lineNumber":121,"sourceCode":"\t\t\t\t\terr,\n\t\t\t\t), nil, nil\n\t\t\t}\n\t\t\tdefer func() { _ = resp.Body.Close() }()\n\n\t\t\tif resp.StatusCode != 200 {\n\t\t\t\tbody, err := io.ReadAll(resp.Body)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to read response body: %w\", err)\n\t\t\t\t}\n\t\t\t\treturn ghErrors.NewGitHubAPIStatusErrorResponse(ctx, \"failed to get commit\", resp, body), nil, nil\n\t\t\t}\n\n\t\t\t// Convert to minimal commit\n\t\t\tminimalCommit := convertToMinimalCommit(commit, detail)\n\n\t\t\tr, err := json.Marshal(minimalCommit)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to marshal response: %w\", err)\n\t\t\t}\n\n\t\t\tresult := utils.NewToolResultText(string(r))\n\t\t\t// Commit content is reachable from the repo's history; in public\n\t\t\t// repos anyone can land it via a PR (untrusted), in private repos\n\t\t\t// only collaborators can (trusted). Confidentiality follows repo\n\t\t\t// visibility.\n\t\t\tresult = attachRepoVisibilityIFCLabel(ctx, deps, client, owner, repo, result, ifc.LabelCommitContents)\n\t\t\treturn result, nil, nil\n\t\t},\n\t)\n}\n\n// ListCommits creates a tool to get the list of commits of a branch in a GitHub\n// repository.\nfunc ListCommits(t translations.TranslationHelperFunc) inventory.ServerTool {\n\tschema := &jsonschema.Schema{\n\t\tType: \"object\",","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/repositories.go#L103-L139","documentation":"After a successful GetCommit, the tool converts the commit to convertToMinimalCommit(commit, detail) and json.Marshals it. Plain data structs cannot make Marshal fail, so this branch is effectively unreachable defensive code; hitting it indicates a type regression (func/chan field, cyclic pointer) in the minimal-commit types rather than bad API data.","triggerScenarios":"A field of unsupported type (func, chan, complex, cyclic pointer) is added to the minimal commit struct family; every get_commit call then fails at marshal time despite the API call succeeding.","commonSituations":"Refactors embedding raw go-github types that carry func fields; computed helpers accidentally stored as fields instead of methods.","solutions":["Review recent edits to convertToMinimalCommit and its return type for non-JSON-safe fields","Add a CI test marshaling a converted commit fixture","Model derived values as precomputed strings/ints, never closures"],"exampleFix":"// before\ntype MinimalCommit struct {\n\tSHA        string      `json:\"sha\"`\n\tMessage    string      `json:\"message\"`\n\tDiffFn     func() string // no json tag, Marshal fails on it\n}\n\n// after\ntype MinimalCommit struct {\n\tSHA        string `json:\"sha\"`\n\tMessage    string `json:\"message\"`\n\tDiffPreview string `json:\"diff_preview,omitempty\"` // precomputed\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"var unsupportedType *json.UnsupportedTypeError\nif errors.As(err, &unsupportedType) {\n\t// regression in MinimalCommit types — file a bug, no operational fix\n}","tryCatchPattern":"r, err := json.Marshal(minimalCommit)\nif err != nil {\n\tlog.Error(\"commit marshal regression\", \"err\", err)\n\treturn nil, nil, fmt.Errorf(\"internal serialization failure: %w\", err)\n}","preventionTips":["Keep Minimal* DTOs acyclic with only string/int/bool fields","Marshal-type coverage tests in CI catch regressions before release","Do not retry — report as a bug with the stack trace"],"tags":["go","json","mcp","serialization","defensive-code"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}