{"record":{"id":"286031544c872919","repo":"crowdsecurity/crowdsec","slug":"invalid-type-for-method-t","errorCode":null,"errorMessage":"invalid type for method: %T","messagePattern":"invalid type for method: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/http.go","lineNumber":116,"sourceCode":"\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for contentType: %T\", params[1])\n\t}\n\n\tbody, ok := params[2].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for body: %T\", params[2])\n\t}\n\n\theaders := map[string]string{\"Content-Type\": contentType}\n\n\treturn doHTTPRequest(http.MethodPost, uri, headers, strings.NewReader(body))\n}\n\n// HTTPRequest(method string, url string, headers map[string]any, body string) (*HTTPResponse, error)\nfunc HTTPRequest(params ...any) (any, error) {\n\tmethod, ok := params[0].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for method: %T\", params[0])\n\t}\n\n\turi, ok := params[1].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for url: %T\", params[1])\n\t}\n\n\t// headers is map[string]any so that expr map literals (map[string]interface{})\n\t// are accepted; values are stringified.\n\trawHeaders, ok := params[2].(map[string]any)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for headers: %T\", params[2])\n\t}\n\n\theaders := make(map[string]string, len(rawHeaders))\n\tfor k, v := range rawHeaders {\n\t\theaders[k] = fmt.Sprint(v)\n\t}","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/http.go#L98-L134","documentation":"HTTPRequest(method, url, headers, body) validates each argument's type in order; this error means the first argument (the HTTP method) was not a string. The method must be a string like 'GET', 'POST'.","triggerScenarios":"HTTPRequest(evt.method, url, {}, \"\") where evt.method is nil or non-string; passing an enum-like constant of non-string type; swapping the first two arguments.","commonSituations":"Method field missing on the event so it evaluates to nil; accidentally passing the URL as first argument; method stored as a parsed token of non-string type.","solutions":["Pass a quoted string literal for the method, e.g. \"GET\"","If the method is dynamic, ensure the field is a string before the call","Verify argument order: HTTPRequest(method, url, headers, body)","Use the %T value in the message to see what was actually passed"],"exampleFix":"// before\nHTTPRequest(evt.http_verb, url, {}, \"\")\n// after\nHTTPRequest(\"GET\", url, {}, \"\")","handlingStrategy":"validation","validationCode":"// pass a string literal: HTTPRequest(\"GET\", ...)","typeGuard":"func isString(v interface{}) bool { _, ok := v.(string); return ok }","tryCatchPattern":null,"preventionTips":["Quote the method literal","Remember argument order: method, url, headers, body","Ensure dynamic method fields are non-nil strings"],"tags":["expr","http","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}