{"record":{"id":"a839a78229f4063f","repo":"github/github-mcp-server","slug":"failed-to-marshal-response-w","errorCode":null,"errorMessage":"failed to marshal response: %w","messagePattern":"failed to marshal response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/github/actions.go","lineNumber":108,"sourceCode":"\t\t\t// Enable reporting of status codes and error causes\n\t\t\t_, _ = ghErrors.NewGitHubAPIErrorToCtx(ctx, \"failed to get job logs\", resp, err) // Explicitly ignore error for graceful handling\n\t\t}\n\n\t\tlogResults = append(logResults, jobResult)\n\t}\n\n\tresult := map[string]any{\n\t\t\"message\":       fmt.Sprintf(\"Retrieved logs for %d failed jobs\", len(failedJobs)),\n\t\t\"run_id\":        runID,\n\t\t\"total_jobs\":    len(jobs.Jobs),\n\t\t\"failed_jobs\":   len(failedJobs),\n\t\t\"logs\":          logResults,\n\t\t\"return_format\": map[string]bool{\"content\": returnContent, \"urls\": !returnContent},\n\t}\n\n\tr, err := json.Marshal(result)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to marshal response: %w\", err)\n\t}\n\n\treturn utils.NewToolResultText(string(r)), nil, nil\n}\n\n// handleSingleJobLogs gets logs for a single job\nfunc handleSingleJobLogs(ctx context.Context, client *github.Client, owner, repo string, jobID int64, returnContent bool, tailLines int, contentWindowSize int) (*mcp.CallToolResult, any, error) {\n\tjobResult, resp, err := getJobLogData(ctx, client, owner, repo, jobID, \"\", returnContent, tailLines, contentWindowSize)\n\tif err != nil {\n\t\treturn ghErrors.NewGitHubAPIErrorResponse(ctx, \"failed to get job logs\", resp, err), nil, nil\n\t}\n\n\tr, err := json.Marshal(jobResult)\n\tif err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"failed to marshal response: %w\", err)\n\t}\n\n\treturn utils.NewToolResultText(string(r)), nil, nil","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/github/github-mcp-server/blob/0ea1f775a7c73eff1bd2e25904d01136756bbfe2/pkg/github/actions.go#L90-L126","documentation":"Defensive guard in handleFailedJobsLogs (pkg/github/actions.go:108): json.Marshal failed on the assembled result map (message, run_id, total_jobs, failed_jobs, logs, return_format). Every value in that map is a string, int, bool, or nested map produced by the server itself, so with well-formed behavior this branch is effectively unreachable; it fires only if a code path injects a non-serializable Go value (func, chan, NaN float, cyclic pointer).","triggerScenarios":"Calling get_action_job_logs / failed-jobs log flows when a regression puts a non-JSON-serializable value into logResults or the result map; JSON cycle detection (\"json: unsupported value: encountered a cycle via ...\") on self-referential structures; math.NaN() floats in numeric fields.","commonSituations":"Almost never seen in production; appears after upgrading to a version with a serialization regression, or in forks that add custom fields (e.g. embedding *bytes.Buffer or a func) to the result map.","solutions":["No input change fixes it - it is a server-side bug: capture the exact tool arguments and open an issue against github-mcp-server","If you maintain the code, keep only JSON-safe primitives (string/int/bool/nested maps) in result maps","Test custom additions with json.Marshal before returning them","Downgrade or upgrade to the nearest release where the tool worked"],"exampleFix":"// before\nr, err := json.Marshal(result)\nif err != nil {\n    return nil, nil, fmt.Errorf(\"failed to marshal response: %w\", err)\n}\n\n// after - keep maps JSON-safe and fail loudly in tests\nr, err := json.Marshal(result)\nif err != nil {\n    return nil, nil, fmt.Errorf(\"failed to marshal response (result keys %v): %w\", reflect.ValueOf(result).MapKeys(), err)\n}","handlingStrategy":"validation","validationCode":"// If you build logResults yourself, assert JSON safety before the tool returns\nif _, err := json.Marshal(logResults); err != nil {\n    return fmt.Errorf(\"non-serializable log result: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    // marshal of server-built data failed: not input-related, surface for triage\n    return fmt.Errorf(\"tool %s marshal failure (server bug?): %w\", toolName, err)\n}","preventionTips":["Treat marshal failures as server bugs - report rather than retry","Pin github-mcp-server versions in production deployments","Keep custom-added result fields to string/int/bool","Add json.Marshal smoke tests over result shapes in CI"],"tags":["json","serialization","github-actions","logs","go"],"backgroundTag":null,"analyzedSha":"0ea1f775a7c73eff1bd2e25904d01136756bbfe2","analyzedAt":"2026-08-15T18:10:19.804Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}