{"record":{"id":"0c09f14622c98f8f","repo":"vxcontrol/pentagi","slug":"failed-to-marshal-request-body-v","errorCode":null,"errorMessage":"failed to marshal request body: %v","messagePattern":"failed to marshal request body: (.+?)","errorType":"exception","errorClass":"FatalError","httpStatus":null,"severity":"error","filePath":"backend/pkg/tools/searchers/firecrawl.go","lineNumber":153,"sourceCode":"\tclient, err := system.GetHTTPClient(f.cfg)\n\tif err != nil {\n\t\treturn \"\", Fatal(fmt.Errorf(\"failed to create http client: %w\", err))\n\t}\n\n\t// sources is intentionally omitted: /v2/search defaults to [\"web\"], which is\n\t// all this tool consumes, and it avoids the string-vs-object shape ambiguity\n\t// that field carries across the API/SDK layers.\n\treqPayload := firecrawlRequest{\n\t\tQuery: query,\n\t\tLimit: maxResults,\n\t\tScrapeOptions: &firecrawlScrapeOptions{\n\t\t\tFormats:         []string{\"markdown\"},\n\t\t\tOnlyMainContent: true,\n\t\t},\n\t}\n\treqBody, err := json.Marshal(reqPayload)\n\tif err != nil {\n\t\treturn \"\", Fatal(fmt.Errorf(\"failed to marshal request body: %v\", err))\n\t}\n\n\treq, err := http.NewRequest(http.MethodPost, f.searchURL(), bytes.NewBuffer(reqBody))\n\tif err != nil {\n\t\treturn \"\", Fatal(fmt.Errorf(\"failed to build request: %v\", err))\n\t}\n\n\treq = req.WithContext(ctx)\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"Authorization\", \"Bearer \"+f.apiKey())\n\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn \"\", Retryable(fmt.Errorf(\"failed to do request: %v\", err), 0)\n\t}\n\tdefer resp.Body.Close()\n\n\treturn f.parseHTTPResponse(ctx, query, resp)","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/tools/searchers/firecrawl.go#L135-L171","documentation":"Before sending the search request, firecrawl marshals its firecrawlRequest payload with encoding/json; failure is wrapped in a FatalError. With the current struct this is practically impossible, so it guards against future type mismatches (e.g. unsupported field types).","triggerScenarios":"json.Marshal(reqPayload) errors — only possible if the payload struct gains unmarshalable fields (chan/func) or a custom MarshalJSON returns an error.","commonSituations":"After code changes introducing non-serializable fields into firecrawlRequest, or a custom marshaller bug.","solutions":["Inspect the wrapped %v cause to find which field fails to marshal.","Audit firecrawlRequest for chan/func/cyclic fields after recent changes.","Fix or remove the offending field, or add a MarshalJSON for it."],"exampleFix":"// before\nTimeout int // custom marshaller returning error\n// after\nTimeout *int  // plain serializable type, or fix MarshalJSON","handlingStrategy":"validation","validationCode":"if _, err := json.Marshal(reqPayload); err != nil {\n  return fmt.Errorf(\"payload not serializable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep firecrawlRequest fields JSON-serializable (no chan/func).","Add a unit test marshalling the request payload.","Review custom MarshalJSON implementations for error returns."],"tags":["json","serialization","firecrawl","searchers"],"backgroundTag":"json-marshal-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}