{"record":{"id":"1038eb026a0967a2","repo":"googleapis/mcp-toolbox","slug":"failed-to-marshal-schema-query-w","errorCode":null,"errorMessage":"failed to marshal schema query: %w","messagePattern":"failed to marshal schema query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/firestore/firestore.go","lineNumber":680,"sourceCode":"\t\t\t})\n\t\t}\n\n\t\tresult = append(result, CollectionSchema{\n\t\t\tCollection: collName,\n\t\t\tFields:     fields,\n\t\t})\n\t}\n\n\treturn result, nil\n}\n\nfunc (s *Source) getSchemaFromPipeline(ctx context.Context, collection string) (CollectionSchema, error) {\n\tgetSchemaQueryBytes, err := json.Marshal(map[string]string{\n\t\t\"collection\": collection,\n\t\t\"semantics\":  \"mongodb\",\n\t})\n\tif err != nil {\n\t\treturn CollectionSchema{}, fmt.Errorf(\"failed to marshal schema query: %w\", err)\n\t}\n\n\tpayload := map[string]any{\n\t\t\"structuredPipeline\": map[string]any{\n\t\t\t\"pipeline\": map[string]any{\n\t\t\t\t\"stages\": []map[string]any{\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\": \"get_schema\",\n\t\t\t\t\t\t\"args\": []map[string]any{\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\"stringValue\": string(getSchemaQueryBytes),\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}","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/firestore/firestore.go#L662-L698","documentation":"getSchemaFromPipeline builds a JSON payload describing a get_schema pipeline request (collection + semantics map) using json.Marshal before POSTing it to the Firestore executePipeline API. This error is thrown if marshaling that simple map[string]string fails — practically only when the encoder cannot serialize the value, which for a map[string]string essentially never happens with valid keys.","triggerScenarios":"json.Marshal of the map {\"collection\":..., \"semantics\":\"mongodb\"} returns an error. With this fixed shape this is nearly impossible; it would require an unsupported value type, which this call site cannot produce.","commonSituations":"Developers who modified the payload to include unsupported types (e.g. channels, funcs, cyclic structures) when extending the query; otherwise seen only in pathological runtime conditions.","solutions":["Inspect recent changes to the payload map for non-JSON-serializable values (channels, funcs, cycles).","Ensure collection is a plain string, not a custom string type with a broken MarshalJSON.","If unexplainable, log err in the wrapped error and test json.Marshal on the payload in isolation."],"exampleFix":"// before: custom type breaks marshaling\ncollection := myCollectionType(\"users\")\ngetSchemaQueryBytes, err := json.Marshal(map[string]string{\"collection\": string-impossible...})\n// after: pass a plain string\ncollection := \"users\"\ngetSchemaQueryBytes, err := json.Marshal(map[string]string{\"collection\": collection, \"semantics\": \"mongodb\"})","handlingStrategy":"validation","validationCode":"if _, err := json.Marshal(map[string]string{\"collection\": coll, \"semantics\": \"mongodb\"}); err != nil {\n    return fmt.Errorf(\"schema query payload is not marshalable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"schema, err := getSchemaFromPipeline(ctx, coll)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to marshal schema query\") {\n        // payload construction bug: inspect inputs for non-string values\n    }\n    return err\n}","preventionTips":["Keep pipeline payload fields as plain strings and JSON-safe types.","Avoid custom string types with MarshalJSON on payload fields.","Cover payload construction with a unit test asserting json.Marshal succeeds."],"tags":["firestore","json-marshal","pipeline","schema-discovery"],"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"}