{"record":{"id":"df933c2b18c37b51","repo":"googleapis/mcp-toolbox","slug":"failed-to-marshal-pipeline-payload-w","errorCode":null,"errorMessage":"failed to marshal pipeline payload: %w","messagePattern":"failed to marshal pipeline payload: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/firestore/firestore.go","lineNumber":911,"sourceCode":"\t\tpayload := map[string]any{\n\t\t\t\"structuredPipeline\": map[string]any{\n\t\t\t\t\"pipeline\": map[string]any{\n\t\t\t\t\t\"stages\": []map[string]any{\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\"name\": \"iql\",\n\t\t\t\t\t\t\t\"args\": []map[string]any{\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\"stringValue\": mqlQuery,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}\n\t\tbodyBytes, err = json.Marshal(payload)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to marshal pipeline payload: %w\", err)\n\t\t}\n\t}\n\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(bodyBytes))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create HTTP request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"User-Agent\", userAgent)\n\treq.Header.Set(\"x-goog-request-params\", fmt.Sprintf(\"project_id=%s&database_id=%s\", s.GetProjectId(), s.GetDatabaseId()))\n\treq.Header.Set(\"x-goog-firestore-api-requester\", \"querydata\")\n\n\tresp, err := httpClient.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to execute pipeline request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n","sourceCodeStart":893,"sourceCodeEnd":929,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/firestore/firestore.go#L893-L929","documentation":"ExecuteMQL constructs a structuredPipeline payload wrapping the MQL query and marshals it with json.Marshal before creating the HTTP request. This error is thrown when that marshaling fails, wrapping the underlying json error.","triggerScenarios":"json.Marshal of the payload map fails — practically only when the payload includes values json cannot encode (channels, funcs, cyclic data) which the fixed structure cannot produce; realistically triggered by code modifications introducing non-serializable fields.","commonSituations":"Custom extensions to ExecuteMQL that inject non-JSON-safe types into the payload; wrapper code passing a struct with unsupported fields.","solutions":["Inspect the payload construction for non-serializable values (channels, funcs, cyclic references).","Ensure the query string and any injected parameters are plain strings/JSON-safe types.","Test json.Marshal(payload) in isolation to surface the exact offending field from the wrapped error."],"exampleFix":"// before: injecting a non-serializable value\npayload[\"params\"] = someFunc\n// after: only JSON-safe values\npayload[\"params\"] = map[string]any{\"q\": queryString}","handlingStrategy":"validation","validationCode":"payload := buildExecutePipelinePayload(query)\nif _, err := json.Marshal(payload); err != nil {\n    return fmt.Errorf(\"pipeline payload not marshalable before ExecuteMQL: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"result, err := src.ExecuteMQL(ctx, query)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to marshal pipeline payload\") {\n        // payload construction bug: inspect payload fields for non-JSON types\n    }\n    return err\n}","preventionTips":["Only put JSON-safe types (string, number, bool, slice, map) into the pipeline payload.","Write a unit test that marshals the exact payload structure ExecuteMQL builds.","Avoid passing user-supplied objects into the payload without converting to strings first."],"tags":["firestore","json-marshal","pipeline","mql"],"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"}