{"record":{"id":"c90285378647add7","repo":"github/github-mcp-server","slug":"failed-to-marshal-response-w-c90285","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/git.go","lineNumber":172,"sourceCode":"\t\t\t\tif entry.Size != nil {\n\t\t\t\t\ttreeEntries[i].Size = entry.Size\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresponse := TreeResponse{\n\t\t\t\tSHA:       *tree.SHA,\n\t\t\t\tTruncated: *tree.Truncated,\n\t\t\t\tTree:      treeEntries,\n\t\t\t\tTreeSHA:   treeSHA,\n\t\t\t\tOwner:     owner,\n\t\t\t\tRepo:      repo,\n\t\t\t\tRecursive: recursive,\n\t\t\t\tCount:     len(filteredEntries),\n\t\t\t}\n\n\t\t\tr, err := json.Marshal(response)\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// The repository tree exposes committed file structure; in public\n\t\t\t// repos anyone can land content via a PR (untrusted), in private\n\t\t\t// repos only collaborators can (trusted). Confidentiality follows\n\t\t\t// repo 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","sourceCodeStart":154,"sourceCodeEnd":185,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/git.go#L154-L185","documentation":"The get_tree handler filters entries from a successful git-trees API response and marshals a struct of strings, *tree.SHA, *tree.Truncated (deref'd bools), the entries slice, ints, and the recursive flag. All are JSON-safe primitives/pointers; json.Marshal can only fail if the entries slice or the struct gains unsupported types (func/channel/NaN) or a cycle. In practice this is a defensive branch guarding future edits.","triggerScenarios":"A refactor appending raw go-github objects with func fields into treeEntries; NaN/Inf float additions (e.g. size as float); self-referential structures if entries ever link parents. Not reachable via any repository tree GitHub can return with the current shape.","commonSituations":"Forks extending tree entries with mode/type objects as non-string types; version upgrades of go-github changing Tree field types from strings to typed structs; copy-paste of the whole *github.TreeEntry into the response.","solutions":["Project each entry into a local struct of string/int fields, as currently done, rather than embedding go-github types","Add a marshal test with a realistic tree fixture to CI","If hit, inspect treeEntries' element type — the bug is local projection, and retrying changes nothing","Keep pointer dereferences guarded (nil *tree.SHA would panic, not marshal-fail; separate concern) so this branch stays the only failure mode"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"r, err := json.Marshal(response)\nif err != nil {\n\treturn nil, nil, fmt.Errorf(\"failed to marshal response: %w\", err)\n}","preventionTips":["Project tree entries into local string/int structs; never embed go-github types in responses","Guard nil pointer derefs (*tree.SHA, *tree.Truncated) before marshaling — nil panics are the neighboring risk","Add a tree-fixture marshal test to catch shape regressions"],"tags":["go","json-marshal","defensive-code","git","trees"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}