{"record":{"id":"6c7e480220a94283","repo":"googleapis/mcp-toolbox","slug":"failed-to-marshal-payload-w-6c7e48","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/looker/lookerconversationalanalytics/lookerconversationalanalytics.go","lineNumber":428,"sourceCode":"\tResultNaturalLanguage string `json:\"resultNaturalLanguage,omitempty\"`\n\tResultCsvData         string `json:\"resultCsvData,omitempty\"`\n\tResultReferenceData   string `json:\"resultReferenceData,omitempty\"`\n\tError                 string `json:\"error,omitempty\"`\n}\ntype AnalysisMessage struct {\n\tQuery         AnalysisQuery `json:\"query,omitempty\"`\n\tProgressEvent AnalysisEvent `json:\"progressEvent,omitempty\"`\n}\n\n// ErrorResponse represents an error message from the API.\ntype ErrorMessage struct {\n\tText string `json:\"text\"`\n}\n\nfunc getStream(ctx context.Context, client *http.Client, url string, payload CAPayload, headers map[string]string) ([]map[string]any, error) {\n\tpayloadBytes, err := json.Marshal(payload)\n\tif err != nil {\n\t\treturn nil, 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 nil, 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 nil, 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":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/tools/looker/lookerconversationalanalytics/lookerconversationalanalytics.go#L410-L446","documentation":"getStream serializes the Conversational Analytics request payload (CAPayload) to JSON before POSTing it. If json.Marshal fails — e.g. the payload contains a value that cannot be marshaled such as a channel, func, or unsupported custom type — the function returns this wrapped error without making the HTTP call.","triggerScenarios":"Constructing a CAPayload whose nested fields (userQueryWithcontext, exploreReferences, options, etc.) include non-JSON-marshalable Go values; programmatic Go callers building the payload manually.","commonSituations":"Custom Go code extending the payload with unsupported field types; cyclic data structures; fields populated from goroutine-unsafe shared state.","solutions":["Inspect the wrapped %w error to find the unmarshalable field","Ensure all CAPayload fields are JSON-safe (strings, slices, maps, numbers)","Remove or convert custom types to primitives before building the payload","Add a unit test marshaling your payload construction path"],"exampleFix":"// before\npayload.Data = make(chan int)\n// after\npayload.Data = map[string]any{\"key\": \"value\"}","handlingStrategy":"try-catch","validationCode":"if err := json.Marshal(payload); err != nil {\n\treturn fmt.Errorf(\"payload not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"resp, err := getStream(ctx, client, url, payload, headers)\nif err != nil {\n\tvar mk *json.MarshalTypeError\n\tif errors.As(err, &mk) {\n\t\tlog.Printf(\"bad field %s at offset %d\", mk.Field, mk.Offset)\n\t}\n\treturn err\n}","preventionTips":["Keep CAPayload fields restricted to JSON-native types","Add round-trip marshal tests for payload builders"],"tags":["looker","json","serialization","http"],"backgroundTag":"json-serialization-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"}