{"record":{"id":"1c7603d2182d42f7","repo":"dgraph-io/dgraph","slug":"invalid-coordinates","errorCode":null,"errorMessage":"Invalid coordinates","messagePattern":"Invalid coordinates","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"types/s2.go","lineNumber":168,"sourceCode":"\t\t\tif err := closed(v); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t}\n\t\treturn g, nil\n\t}\n\n\tvar g geojson.Geometry\n\tif err := json.Unmarshal([]byte(str), &g); err == nil {\n\t\tt, err := g.Decode()\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn validate(t)\n\t}\n\n\ts := x.WhiteSpace.Replace(str)\n\tif len(s) < 5 { // [1,2]\n\t\treturn nil, errors.Errorf(\"Invalid coordinates\")\n\t}\n\tvar m json.RawMessage\n\tvar err error\n\n\tif s[0:4] == \"[[[[\" {\n\t\tg.Type = \"MultiPolygon\"\n\t\terr = m.UnmarshalJSON([]byte(s))\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"Invalid coordinates\")\n\t\t}\n\t\tg.Coordinates = &m\n\t\tg1, err := g.Decode()\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"Invalid coordinates\")\n\t\t}\n\t\treturn validate(g1)\n\t}\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/types/s2.go#L150-L186","documentation":"Thrown by convertToGeom when the whitespace-stripped coordinate string is shorter than 5 characters (the minimum for a minimal coordinate pair like [1,2]). The string cannot possibly contain a valid geometry, so parsing is aborted before JSON decode.","triggerScenarios":"Calling GetGeoTokens/convertToGeom with strings like '', '[]', '[1]', or '  [  ' — anything under 5 chars after whitespace removal.","commonSituations":"Empty database fields, truncated GeoJSON in transit, or callers passing raw lat/lon numbers ('37.7') instead of a GeoJSON coordinate array.","solutions":["Pass a well-formed GeoJSON coordinate string such as \"[1,2]\" or deeper nesting","Check input length/non-emptiness before invoking geo conversion","Fix upstream serialization so the full coordinates JSON is stored/sent"],"exampleFix":"// before\ngeom, err := convertToGeom(\"[1\")\n// after\ngeom, err := convertToGeom(\"[1,2]\")","handlingStrategy":"validation","validationCode":"s := strings.Join(strings.Fields(str), \"\")\nif len(s) < 5 {\n    return errors.New(\"coordinates too short to be valid GeoJSON\")\n}","typeGuard":null,"tryCatchPattern":"g, err := types.ConvertToGeom(str)\nif err != nil && strings.Contains(err.Error(), \"Invalid coordinates\") && len(strings.TrimSpace(str)) < 5 {\n    // reject empty/truncated geometry input\n}","preventionTips":["Never pass empty or raw scalar coordinates to geo conversion","Ensure serialization round-trips preserve full coordinates JSON","Add input-length assertions before calling geometry APIs"],"tags":["geojson","coordinates","validation"],"backgroundTag":"invalid-geojson-coordinates","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}