{"record":{"id":"55ee4afd22b5b7ea","repo":"dgraph-io/dgraph","slug":"error-while-trying-to-parse-value-v-as-geo-val","errorCode":null,"errorMessage":"error while trying to parse value: %+v as geo val","messagePattern":"error while trying to parse value: %\\+v as geo val","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"chunker/json_parser.go","lineNumber":283,"sourceCode":"func (buf *NQuadBuffer) checkForDeletion(mr mapResponse, m map[string]interface{}, op int) {\n\t// Since uid is the only key, this must be S * * deletion.\n\tif op == DeleteNquads && len(mr.uid) > 0 && len(m) == 1 && len(mr.rawFacets) == 0 {\n\t\tbuf.Push(&api.NQuad{\n\t\t\tSubject:     mr.uid,\n\t\t\tPredicate:   x.Star,\n\t\t\tNamespace:   mr.namespace,\n\t\t\tObjectValue: &api.Value{Val: &api.Value_DefaultVal{DefaultVal: x.Star}},\n\t\t})\n\t}\n}\n\nfunc handleGeoType(val map[string]interface{}, nq *api.NQuad) (bool, error) {\n\t_, hasType := val[\"type\"]\n\t_, hasCoordinates := val[\"coordinates\"]\n\tif len(val) == 2 && hasType && hasCoordinates {\n\t\tb, err := json.Marshal(val)\n\t\tif err != nil {\n\t\t\treturn false, fmt.Errorf(\"error while trying to parse value: %+v as geo val\", val)\n\t\t}\n\t\tok, err := tryParseAsGeo(b, nq)\n\t\tif err != nil && ok {\n\t\t\treturn true, err\n\t\t}\n\t\tif ok {\n\t\t\treturn true, nil\n\t\t}\n\t}\n\treturn false, nil\n}\n\nfunc tryParseAsGeo(b []byte, nq *api.NQuad) (bool, error) {\n\tvar g geom.T\n\terr := geojson.Unmarshal(b, &g)\n\tif err != nil {\n\t\treturn false, nil\n\t}","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/chunker/json_parser.go#L265-L301","documentation":"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.","triggerScenarios":"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).","commonSituations":"Constructing maps in Go code with values that json.Marshal cannot serialize (NaN/Inf floats, channels, funcs) before handing them to the parser.","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."],"exampleFix":"// before\nval := map[string]interface{}{\"type\": \"Point\", \"coordinates\": []float64{math.NaN(), 2}}\n// after\nval := map[string]interface{}{\"type\": \"Point\", \"coordinates\": []float64{0, 2}}","handlingStrategy":"validation","validationCode":"func geoMarshalable(val map[string]interface{}) error {\n\t_, err := json.Marshal(val) // must succeed\n\treturn err\n}","typeGuard":"func looksLikeGeo(val map[string]interface{}) bool {\n\tif len(val) != 2 {\n\t\treturn false\n\t}\n\tt, ok1 := val[\"type\"].(string)\n\t_, ok2 := val[\"coordinates\"]\n\treturn ok1 && ok2 && t != \"\"\n}","tryCatchPattern":"if err := buf.ParseJSON(b, op); err != nil && strings.Contains(err.Error(), \"as geo val\") {\n\t// locate the map value and fix its non-serializable members\n}","preventionTips":["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"],"tags":["json-parser","geo","serialization","dgraph"],"backgroundTag":"geo-value-parse-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}