{"record":{"id":"59da7cb9eea1fb7d","repo":"googleapis/mcp-toolbox","slug":"failed-to-marshal-query-body-w","errorCode":null,"errorMessage":"failed to marshal query body: %w","messagePattern":"failed to marshal query body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/elasticsearch/elasticsearch.go","lineNumber":179,"sourceCode":"\tType string `json:\"type\"`\n}\n\ntype EsqlResult struct {\n\tColumns []EsqlColumn `json:\"columns\"`\n\tValues  [][]any      `json:\"values\"`\n}\n\nfunc (s *Source) RunSQL(ctx context.Context, format, query string, params []map[string]any) (any, error) {\n\tbodyStruct := struct {\n\t\tQuery  string           `json:\"query\"`\n\t\tParams []map[string]any `json:\"params,omitempty\"`\n\t}{\n\t\tQuery:  query,\n\t\tParams: params,\n\t}\n\tbody, err := json.Marshal(bodyStruct)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal query body: %w\", err)\n\t}\n\n\tres, err := esapi.EsqlQueryRequest{\n\t\tBody:       bytes.NewReader(body),\n\t\tFormat:     format,\n\t\tFilterPath: []string{\"columns\", \"values\"},\n\t\tInstrument: s.ElasticsearchClient().InstrumentationEnabled(),\n\t}.Do(ctx, s.ElasticsearchClient())\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer res.Body.Close()\n\n\tif res.IsError() {\n\t\t// Try to extract error message from response\n\t\tvar esErr json.RawMessage\n\t\terr = util.DecodeJSON(res.Body, &esErr)","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/elasticsearch/elasticsearch.go#L161-L197","documentation":"Thrown in RunSQL when json.Marshal fails to serialize the ES|QL request body ({query, params}). In practice the query string and params slice are always JSON-serializable, so this is a defensive wrapper around an almost-impossible failure mode.","triggerScenarios":"Only if params contains values json.Marshal cannot handle — e.g. channel, func, or cyclic data structures injected programmatically rather than through normal tool invocation.","commonSituations":"Custom tool code passing non-JSON-serializable parameter maps directly to RunSQL; virtually never seen through standard YAML-configured tool invocation.","solutions":["Inspect any custom code that builds the `params` argument and remove non-serializable values (func, channel, cyclic maps)","Ensure params is []map[string]any containing only JSON-compatible values","If it persists, log the wrapped underlying error (%w) for the offending value"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure params are JSON-serializable before calling RunSQL\nif _, err := json.Marshal(params); err != nil {\n    return fmt.Errorf(\"params not JSON-serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass []map[string]any values built from JSON-decoded input","Never inject Go-native values like func or channel into query params","This error is near-impossible via normal tool invocation; suspect custom code"],"tags":["serialization","json","elasticsearch"],"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"}