{"record":{"id":"16094ab6d836360a","repo":"projectdiscovery/subfinder","slug":"failed-to-marshal-request-body-w","errorCode":null,"errorMessage":"failed to marshal request body: %w","messagePattern":"failed to marshal request body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/subscraping/sources/pugrecon/pugrecon.go","lineNumber":62,"sourceCode":"\ts.requests = 0\n\n\tgo func() {\n\t\tdefer func(startTime time.Time) {\n\t\t\ts.timeTaken = time.Since(startTime)\n\t\t\tclose(results)\n\t\t}(time.Now())\n\n\t\trandomApiKey := subscraping.PickRandom(s.apiKeys, s.Name())\n\t\tif randomApiKey == \"\" {\n\t\t\ts.skipped = true\n\t\t\treturn\n\t\t}\n\n\t\t// Prepare POST request data\n\t\tpostData := map[string]string{\"domain_name\": domain}\n\t\tbodyBytes, err := json.Marshal(postData)\n\t\tif err != nil {\n\t\t\tresults <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: fmt.Errorf(\"failed to marshal request body: %w\", err)}\n\t\t\ts.errors++\n\t\t\treturn\n\t\t}\n\t\tbodyReader := bytes.NewReader(bodyBytes)\n\n\t\t// Prepare headers\n\t\theaders := map[string]string{\n\t\t\t\"Authorization\": \"Bearer \" + randomApiKey,\n\t\t\t\"Content-Type\":  \"application/json\",\n\t\t\t\"Accept\":        \"application/json\",\n\t\t}\n\n\t\tapiURL := \"https://pugrecon.com/api/v1/domains\"\n\t\ts.requests++\n\t\tresp, err := session.HTTPRequest(ctx, http.MethodPost, apiURL, \"\", headers, bodyReader, subscraping.BasicAuth{}) // Use HTTPRequest for full header control\n\t\tif err != nil {\n\t\t\tresults <- subscraping.Result{Source: s.Name(), Type: subscraping.Error, Error: err}\n\t\t\ts.errors++","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/projectdiscovery/subfinder/blob/7a0b91f0fac01b62c65328bd771a3560ae611d6a/pkg/subscraping/sources/pugrecon/pugrecon.go#L44-L80","documentation":"PugRecon source marshals {\"domain_name\": <domain>} as the POST body. If json.Marshal fails, an Error result wrapping the original error is emitted and enumeration stops for this source. With a simple map[string]string this is effectively unreachable except in broken builds.","triggerScenarios":"json.Marshal(postData) errors while preparing the PugRecon POST request for a domain — practically only with a modified payload structure containing non-marshalable values.","commonSituations":"Custom forks that added unsupported field types; corrupted toolchain builds; essentially never in stock subfinder.","solutions":["Verify the postData map contains only marshalable string values","Rebuild from unmodified upstream pugrecon.go","Read the wrapped %w cause in the error result to identify the offending field"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// postData is map[string]string — always marshalable; validate domain non-empty before building\nif domain == \"\" { return errors.New(\"domain is required\") }","typeGuard":null,"tryCatchPattern":"if err != nil {\n\treturn fmt.Errorf(\"failed to marshal request body: %w\", err)\n}","preventionTips":["Keep POST payload to simple string fields","Always wrap marshal errors with %w"],"tags":["go","json-marshal","pugrecon"],"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"}