{"record":{"id":"6fc8c5e3fd97e9de","repo":"crowdsecurity/crowdsec","slug":"long2-is-not-a-float-v","errorCode":null,"errorMessage":"long2 is not a float : %v","messagePattern":"long2 is not a float : (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/helpers.go","lineNumber":416,"sourceCode":"\tlong1f, err := strconv.ParseFloat(long1, 64)\n\tif err != nil {\n\t\tlog.Warningf(\"long1 is not a float : %v\", err)\n\n\t\treturn 0.0, fmt.Errorf(\"long1 is not a float : %v\", err)\n\t}\n\n\tlat2f, err := strconv.ParseFloat(lat2, 64)\n\tif err != nil {\n\t\tlog.Warningf(\"lat2 is not a float : %v\", err)\n\n\t\treturn 0.0, fmt.Errorf(\"lat2 is not a float : %v\", err)\n\t}\n\n\tlong2f, err := strconv.ParseFloat(long2, 64)\n\tif err != nil {\n\t\tlog.Warningf(\"long2 is not a float : %v\", err)\n\n\t\treturn 0.0, fmt.Errorf(\"long2 is not a float : %v\", err)\n\t}\n\n\t// either set of coordinates is 0,0, return 0 to avoid FPs\n\tif (lat1f == 0.0 && long1f == 0.0) || (lat2f == 0.0 && long2f == 0.0) {\n\t\tlog.Warningf(\"one of the coordinates is 0,0, returning 0\")\n\t\treturn 0.0, nil\n\t}\n\n\tfirst := haversine.Coord{Lat: lat1f, Lon: long1f}\n\tsecond := haversine.Coord{Lat: lat2f, Lon: long2f}\n\n\t_, km := haversine.Distance(first, second)\n\n\treturn km, nil\n}\n\n// func QueryEscape(s string) string {\nfunc QueryEscape(params ...any) (any, error) {","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/helpers.go#L398-L434","documentation":"The Distance expr helper parses long2 as its final coordinate conversion. This error is thrown when the long2 argument cannot be parsed by strconv.ParseFloat; the helper logs a warning and returns (0.0, error).","triggerScenarios":"Calling exprhelpers.Distance where long2 is non-numeric — empty string from failed enrichment, \"-0.1278 E\" with a direction suffix, or a comma-decimal string.","commonSituations":"Reference coordinates configured in a config file with locale formatting; fields sourced from logs that embed units; typo in the variable name causing an empty string to be interpolated.","solutions":["Pass long2 as a plain decimal string such as \"-0.1278\".","Fix locale formatting (comma decimals, units, hemisphere letters) before the value reaches the helper.","Verify the interpolated variable is populated — a typo or missing field yields \"\" which always fails.","Add an expression-level numeric guard so Distance is only evaluated with all four valid coordinates."],"exampleFix":"// before\nDistance(lat1, long1, lat2, \"-0,1278\")\n// after\nDistance(lat1, long1, lat2, \"-0.1278\")","handlingStrategy":"validation","validationCode":"if _, err := strconv.ParseFloat(long2, 64); err != nil {\n\t// skip Distance call\n}","typeGuard":"func isFloat(s string) bool {\n\t_, err := strconv.ParseFloat(s, 64)\n\treturn err == nil\n}","tryCatchPattern":"expr: validate all four coordinates with isNumeric before Distance; on failure, take a non-scoring branch instead of relying on the 0.0 return","preventionTips":["Fix locale decimal commas in reference coordinates stored in config","Double-check interpolated variable names — an empty interpolation always fails ParseFloat","Add a single shared numeric-normalization step for all four geo fields"],"tags":["geo","parsing","expr","crowdsec"],"backgroundTag":"invalid-argument-format","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"}