{"record":{"id":"0afa00461ff1e90a","repo":"crowdsecurity/crowdsec","slug":"invalid-type-for-contenttype-t","errorCode":null,"errorMessage":"invalid type for contentType: %T","messagePattern":"invalid type for contentType: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/http.go","lineNumber":99,"sourceCode":"func HTTPHead(params ...any) (any, error) {\n\turi, ok := params[0].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for url: %T\", params[0])\n\t}\n\n\treturn doHTTPRequest(http.MethodHead, uri, nil, nil)\n}\n\n// HTTPPost(url string, contentType string, body string) (*HTTPResponse, error)\nfunc HTTPPost(params ...any) (any, error) {\n\turi, ok := params[0].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for url: %T\", params[0])\n\t}\n\n\tcontentType, ok := params[1].(string)\n\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}","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/http.go#L81-L117","documentation":"The HTTPPost expr helper was called with params[1] (the contentType argument) not a string. This is a type-check guard for the variadic ...any signature — the expression passed e.g. a number where the body content-type string is expected; %T reveals the actual type.","triggerScenarios":"HTTPPost(url, 42, body), HTTPPost(url, nil, body), or passing a variable that holds a non-string value in the contentType position.","commonSituations":"Content type field read from config/event as non-string; argument order mistake (e.g. body passed as second arg, shifting contentType); nil placeholder used for an optional header.","solutions":["Pass a literal string content type such as \"application/json\"","If the content type is dynamic, ensure the field is a string before calling","Check argument order: HTTPPost(url, contentType, body)","Inspect the %T in the message to confirm which wrong type was supplied"],"exampleFix":"// before\nHTTPPost(\"http://example.com\", application_json, \"{}\")\n// after\nHTTPPost(\"http://example.com\", \"application/json\", \"{}\")","handlingStrategy":"type-guard","validationCode":"// always pass a string literal:\n// HTTPPost(url, \"application/json\", body)","typeGuard":"func isString(v interface{}) bool { _, ok := v.(string); return ok }","tryCatchPattern":null,"preventionTips":["Use quoted string literals for contentType","Keep HTTPPost argument order in mind: url, contentType, body","Verify dynamic content-type fields are string-typed"],"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-14T00:17:10.932Z"}