crowdsecurity/crowdsec · error
long2 is not a float : %v
Error message
long2 is not a float : %v
What it means
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).
Source
Thrown at pkg/exprhelpers/helpers.go:416
long1f, err := strconv.ParseFloat(long1, 64)
if err != nil {
log.Warningf("long1 is not a float : %v", err)
return 0.0, fmt.Errorf("long1 is not a float : %v", err)
}
lat2f, err := strconv.ParseFloat(lat2, 64)
if err != nil {
log.Warningf("lat2 is not a float : %v", err)
return 0.0, fmt.Errorf("lat2 is not a float : %v", err)
}
long2f, err := strconv.ParseFloat(long2, 64)
if err != nil {
log.Warningf("long2 is not a float : %v", err)
return 0.0, fmt.Errorf("long2 is not a float : %v", err)
}
// either set of coordinates is 0,0, return 0 to avoid FPs
if (lat1f == 0.0 && long1f == 0.0) || (lat2f == 0.0 && long2f == 0.0) {
log.Warningf("one of the coordinates is 0,0, returning 0")
return 0.0, nil
}
first := haversine.Coord{Lat: lat1f, Lon: long1f}
second := haversine.Coord{Lat: lat2f, Lon: long2f}
_, km := haversine.Distance(first, second)
return km, nil
}
// func QueryEscape(s string) string {
func QueryEscape(params ...any) (any, error) {View on GitHub (pinned to 909b515798)
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.
Example fix
// before Distance(lat1, long1, lat2, "-0,1278") // after Distance(lat1, long1, lat2, "-0.1278")
Defensive patterns
Strategy: validation
Validate before calling
if _, err := strconv.ParseFloat(long2, 64); err != nil {
// skip Distance call
} Type guard
func isFloat(s string) bool {
_, err := strconv.ParseFloat(s, 64)
return err == nil
} Try / catch
expr: validate all four coordinates with isNumeric before Distance; on failure, take a non-scoring branch instead of relying on the 0.0 return
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- lat1 is not a float : %v
- long1 is not a float : %v
- lat2 is not a float : %v
- unable to parse time
- unable to parse duration
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/6fc8c5e3fd97e9de.
Report an issue: GitHub.