{"record":{"id":"b311dec85046c529","repo":"projectdiscovery/subfinder","slug":"error-marshaling-request-body","errorCode":null,"errorMessage":"error marshaling request body","messagePattern":"error marshaling request body","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/subscraping/sources/netlas/netlas.go","lineNumber":118,"sourceCode":"\t\tif err != nil {\n\t\t\tresults <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}\n\t\t\ts.errors++\n\t\t\treturn\n\t\t}\n\n\t\t// Make a single POST request to get all domains via download method\n\n\t\tapiUrl := \"https://app.netlas.io/api/domains/download/\"\n\t\tquery := fmt.Sprintf(\"domain:*.%s AND NOT domain:%s\", domain, domain)\n\t\trequestBody := map[string]any{\n\t\t\t\"q\":           query,\n\t\t\t\"fields\":      []string{\"*\"},\n\t\t\t\"source_type\": \"include\",\n\t\t\t\"size\":        min(domainsCount.Count, communityDownloadCap),\n\t\t}\n\t\tjsonRequestBody, err := json.Marshal(requestBody)\n\t\tif err != nil {\n\t\t\tresults <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf(\"error marshaling request body\")}\n\t\t\ts.errors++\n\t\t\treturn\n\t\t}\n\n\t\t// Pick an API key\n\t\trandomApiKey = subscraping.PickRandom(s.apiKeys, s.Name())\n\n\t\ts.requests++\n\t\tresp2, err := session.HTTPRequest(ctx, http.MethodPost, apiUrl, \"\", map[string]string{\n\t\t\t\"accept\":       \"application/json\",\n\t\t\t\"X-API-Key\":    randomApiKey,\n\t\t\t\"Content-Type\": \"application/json\"}, strings.NewReader(string(jsonRequestBody)), subscraping.BasicAuth{})\n\t\tif err != nil {\n\t\t\tresults <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}\n\t\t\ts.errors++\n\t\t\tsession.DiscardHTTPResponse(resp2)\n\t\t\treturn\n\t\t}","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/projectdiscovery/subfinder/blob/7a0b91f0fac01b62c65328bd771a3560ae611d6a/pkg/subscraping/sources/netlas/netlas.go#L100-L136","documentation":"Netlas source in subscraping marshals a JSON request body (fields, source_type, size) before sending its POST search query. If json.Marshal fails, the query never proceeds and an Error result with this static message is emitted. Because the payload is a plain map of strings/ints this is nearly impossible in practice, but the guard is there for safety.","triggerScenarios":"json.Marshal(requestBody) returns an error while building the Netlas community-download POST body (fields:\"*\", source_type:\"include\", size=min(domainsCount.Count, communityDownloadCap)). In practice only if requestBody contains an unsupported type.","commonSituations":"Practically never triggered for this fixed payload; if seen it indicates a modified/custom build where the body contains channels, funcs, or cyclic structures, or a corrupted local build of the source.","solutions":["Inspect the requestBody construction in pkg/subscraping/sources/netlas/netlas.go for any non-marshalable fields","Rebuild against an unmodified upstream version of the netlas source file","Wrap json.Marshal yourself with %w to see the underlying marshal error instead of the static message"],"exampleFix":"// before\nError: fmt.Errorf(\"error marshaling request body\")\n// after\nError: fmt.Errorf(\"error marshaling request body: %w\", err)","handlingStrategy":"validation","validationCode":"// Marshal is deterministic for the fixed payload; nothing to pre-validate.\nif _, err := json.Marshal(requestBody); err != nil {\n\t// log underlying err — indicates a broken custom build\n}","typeGuard":null,"tryCatchPattern":"// in Go: check err from json.Marshal and surface it with %w\nif err != nil {\n\treturn fmt.Errorf(\"error marshaling request body: %w\", err)\n}","preventionTips":["Keep the netlas source's requestBody to plain string/int fields","When customizing, wrap marshal errors with %w for diagnosis"],"tags":["go","json-marshal","netlas"],"backgroundTag":"json-marshal-failed","analyzedSha":"7a0b91f0fac01b62c65328bd771a3560ae611d6a","analyzedAt":"2026-09-06T23:52:02.109Z","contentChangedAt":"2026-09-06T23:52:02.109Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}