crowdsecurity/crowdsec · error
lat2 is not a float : %v
Error message
lat2 is not a float : %v
What it means
The Distance expr helper parses lat2 with strconv.ParseFloat as its third coordinate conversion. This error is thrown when the lat2 argument is not a valid float string; the helper logs a warning and returns (0.0, error).
Source
Thrown at pkg/exprhelpers/helpers.go:409
lat1f, err := strconv.ParseFloat(lat1, 64)
if err != nil {
log.Warningf("lat1 is not a float : %v", err)
return 0.0, fmt.Errorf("lat1 is not a float : %v", err)
}
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}
View on GitHub (pinned to 909b515798)
Solutions
- Ensure lat2 is a clean decimal string like "51.5074" before calling Distance.
- Trim whitespace/BOM and validate numeric format in the parser stage.
- Skip the Distance call in the expression when the reference event lacks geolocation enrichment.
- Note ParseFloat accepts forms like "1e2" and "Inf" — validate against a strict decimal pattern if that's unwanted.
Example fix
// before Distance(lat1, long1, evt.Enriched.geo.latitude, long2) // empty when enrichment missing // after lat2 != "" && Distance(lat1, long1, lat2, long2) > 100
Defensive patterns
Strategy: validation
Validate before calling
if _, err := strconv.ParseFloat(lat2, 64); err != nil {
// skip Distance call
} Type guard
func isFloat(s string) bool {
_, err := strconv.ParseFloat(s, 64)
return err == nil
} Try / catch
expr: require lat2 != "" (and isNumeric(lat2)) before Distance; fall back to an explicit 'no-data' branch rather than 0.0
Prevention
- Trim whitespace/BOM from extracted fields before numeric conversion
- Skip geo-distance logic when the reference event has no geolocation
- Remember ParseFloat accepts "1e2"/"Inf" — use a strict decimal regex if that matters
When it happens
Trigger: Calling exprhelpers.Distance where lat2 is non-numeric — missing enrichment field (""), scientific-notation garbage, or a string with spaces (" 48.8566").
Common situations: Second event's geolocation missing because its IP had no GeoIP data; whitespace or BOM characters in fields extracted from logs; parsing a hex or other non-decimal representation.
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
- long2 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/3d5c201d5fbb61b7.
Report an issue: GitHub.