{"record":{"id":"259cebf020c9e81e","repo":"googleapis/mcp-toolbox","slug":"failed-to-marshal-payload-w","errorCode":null,"errorMessage":"failed to marshal payload: %w","messagePattern":"failed to marshal payload: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go","lineNumber":272,"sourceCode":"\t\t// getStream wraps network errors or non-200 responses\n\t\treturn nil, util.NewClientServerError(\"failed to get response from conversational analytics API\", http.StatusInternalServerError, err)\n\t}\n\n\treturn response, nil\n}\n\nfunc (t Tool) RequiresClientAuthorization(source sources.Source) (bool, error) {\n\ts, ok := source.(compatibleSource)\n\tif !ok {\n\t\treturn false, fmt.Errorf(\"invalid source for %q tool: source %q is not a compatible type\", t.Cfg.Type, t.Cfg.Source)\n\t}\n\treturn s.UseClientAuthorization(), nil\n}\n\nfunc getStream(client *http.Client, url string, payload CAPayload, headers map[string]string, maxRows int) (string, error) {\n\tpayloadBytes, err := json.Marshal(payload)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to marshal payload: %w\", err)\n\t}\n\n\treq, err := http.NewRequest(\"POST\", url, bytes.NewBuffer(payloadBytes))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to create request: %w\", err)\n\t}\n\tfor k, v := range headers {\n\t\treq.Header.Set(k, v)\n\t}\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to send request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tbody, _ := io.ReadAll(resp.Body)","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/bigquery/bigqueryconversationalanalytics/bigqueryconversationalanalytics.go#L254-L290","documentation":"getStream marshals the Conversational Analytics API request payload (CAPayload) to JSON before sending the POST. This error wraps any failure from json.Marshal of that payload. In practice this is rare because CAPayload contains only JSON-serializable fields; it indicates the payload structure became non-marshalable (e.g. custom types with unsupported fields).","triggerScenarios":"Calling Invoke on the bigquery-conversational-analytics tool when the constructed CAPayload (messages, inlineContext, clientIdEnum) cannot be serialized by encoding/json — e.g. a corrupted/modified payload type containing channels, funcs, or cycles.","commonSituations":"Custom forks that added unsupported field types to CAPayload or Message; Go version/library changes changing marshal behavior; transient logic bugs injecting nil or cyclic data into the payload.","solutions":["Check for local modifications or forks that added non-JSON-serializable fields to CAPayload/Message and fix their types.","Ensure the user text and table references passed to Invoke contain no unsupported characters/types by logging the payload before marshaling.","Rebuild against the upstream version of the toolbox to rule out local drift, then retry Invoke."],"exampleFix":"// before: cyclic/unsupported field in payload\ntype CAPayload struct { Messages []Message; Callback func() }\n// after: keep payload JSON-only\ntype CAPayload struct { Messages []Message `json:\"messages\"`; InlineContext InlineContext `json:\"inlineContext\"`; ClientIdEnum string `json:\"clientIdEnum\"` }","handlingStrategy":"try-catch","validationCode":"if _, err := json.Marshal(payload); err != nil {\n    return fmt.Errorf(\"payload not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"result, err := tool.Invoke(ctx, params)\nif err != nil && strings.Contains(err.Error(), \"failed to marshal payload\") {\n    log.Printf(\"payload construction bug: %v\", err)\n    return fmt.Errorf(\"internal payload error: %w\", err)\n}","preventionTips":["Keep CAPayload limited to JSON-serializable field types.","Add a unit test that marshals a fully populated CAPayload.","Avoid injecting untyped/any values into request structs."],"tags":["go","json","serialization","bigquery"],"backgroundTag":"json-marshal-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}