dgraph-io/dgraph · error
error while trying to parse value: %+v as geo val
Error message
error while trying to parse value: %+v as geo val
What it means
handleGeoType (chunker/json_parser.go:283) treats a map containing exactly "type" and "coordinates" as a candidate geo JSON value. If marshaling that map back to JSON fails, the value cannot be processed as a geo value and this error is returned. It signals the geo JSON structure was recognized by shape but could not be re-encoded.
Source
Thrown at chunker/json_parser.go:283
func (buf *NQuadBuffer) checkForDeletion(mr mapResponse, m map[string]interface{}, op int) {
// Since uid is the only key, this must be S * * deletion.
if op == DeleteNquads && len(mr.uid) > 0 && len(m) == 1 && len(mr.rawFacets) == 0 {
buf.Push(&api.NQuad{
Subject: mr.uid,
Predicate: x.Star,
Namespace: mr.namespace,
ObjectValue: &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}},
})
}
}
func handleGeoType(val map[string]interface{}, nq *api.NQuad) (bool, error) {
_, hasType := val["type"]
_, hasCoordinates := val["coordinates"]
if len(val) == 2 && hasType && hasCoordinates {
b, err := json.Marshal(val)
if err != nil {
return false, fmt.Errorf("error while trying to parse value: %+v as geo val", val)
}
ok, err := tryParseAsGeo(b, nq)
if err != nil && ok {
return true, err
}
if ok {
return true, nil
}
}
return false, nil
}
func tryParseAsGeo(b []byte, nq *api.NQuad) (bool, error) {
var g geom.T
err := geojson.Unmarshal(b, &g)
if err != nil {
return false, nil
}View on GitHub (pinned to 759e242be6)
Solutions
- Ensure the "type" and "coordinates" values are plain JSON-serializable types (string and []float64).
- Validate the map with json.Marshal yourself before calling the parser to catch unencodable values.
- Replace NaN/Inf or non-serializable coordinate values with finite numbers.
Example fix
// before
val := map[string]interface{}{"type": "Point", "coordinates": []float64{math.NaN(), 2}}
// after
val := map[string]interface{}{"type": "Point", "coordinates": []float64{0, 2}} Defensive patterns
Strategy: validation
Validate before calling
func geoMarshalable(val map[string]interface{}) error {
_, err := json.Marshal(val) // must succeed
return err
} Type guard
func looksLikeGeo(val map[string]interface{}) bool {
if len(val) != 2 {
return false
}
t, ok1 := val["type"].(string)
_, ok2 := val["coordinates"]
return ok1 && ok2 && t != ""
} Try / catch
if err := buf.ParseJSON(b, op); err != nil && strings.Contains(err.Error(), "as geo val") {
// locate the map value and fix its non-serializable members
} Prevention
- Keep coordinates as []float64 with finite values (no NaN/Inf)
- Marshal-test geo objects before passing them to the parser
- Build geo values only through helper constructors, not ad-hoc maps
When it happens
Trigger: Calling ParseJSON/FastParseJSON with an attribute value that is a map with exactly the keys "type" and "coordinates" (e.g. {"type":"Point","coordinates":[1,2]}), where json.Marshal of that map returns an error (rare: e.g. unsupported value types inside, such as channels or NaN floats injected programmatically).
Common situations: Constructing maps in Go code with values that json.Marshal cannot serialize (NaN/Inf floats, channels, funcs) before handing them to the parser.
Related errors
- couldn't convert value: %s to geo type
- unexpected type for val for attr: %s while converting to nqu
- got unsupported type for list: %s
- only array of map allowed at root
- initial element not found in json
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/55ee4afd22b5b7ea.
Report an issue: GitHub.