{"record":{"id":"ecc2604c14f7a74a","repo":"databendlabs/databend","slug":"polygon-geometry","errorCode":null,"errorMessage":"polygon geometry","messagePattern":"polygon geometry","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/expression/src/geographic/aggregate.rs","lineNumber":112,"sourceCode":"                .collect();\n            let multi_point = MultiPoint::from_iter(points);\n            return Ok(Some(Geometry::MultiPoint(multi_point)));\n        }\n        if geos\n            .iter()\n            .all(|geo| matches!(geo, Geometry::LineString(_)))\n        {\n            let lines: Vec<LineString<f64>> = geos\n                .into_iter()\n                .map(|geo| geo.try_into().expect(\"linestring geometry\"))\n                .collect();\n            let multi_line_string = MultiLineString::from_iter(lines);\n            return Ok(Some(Geometry::MultiLineString(multi_line_string)));\n        }\n        if geos.iter().all(|geo| matches!(geo, Geometry::Polygon(_))) {\n            let polygons: Vec<Polygon<f64>> = geos\n                .into_iter()\n                .map(|geo| geo.try_into().expect(\"polygon geometry\"))\n                .collect();\n            let multi_polygon = MultiPolygon::from_iter(polygons);\n            return Ok(Some(Geometry::MultiPolygon(multi_polygon)));\n        }\n\n        let collection = GeometryCollection::from_iter(geos);\n        Ok(Some(Geometry::GeometryCollection(collection)))\n    }\n\n    fn binary_compute(l_geo: Geometry<f64>, r_geo: Geometry<f64>) -> Result<Option<Geometry<f64>>> {\n        Self::compute(vec![l_geo, r_geo])\n    }\n}\n\npub struct EnvelopeAggOp;\n\nimpl GeoAggOp for EnvelopeAggOp {\n    fn compute(geos: Vec<Geometry<f64>>) -> Result<Option<Geometry<f64>>> {","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/expression/src/geographic/aggregate.rs#L94-L130","documentation":"In geographic aggregate `compute`, when all geometries are `Geometry::Polygon(_)`, each is converted to `Polygon<f64>` with `try_into().expect(\"polygon geometry\")` to build a MultiPolygon. The type guard makes failure theoretically impossible, so this panic indicates the Polygon TryFrom impl rejected a guarded value — an internal invariant violation or bad polygon data.","triggerScenarios":"Aggregating polygon geometries where the `TryFrom<Geometry> for Polygon<f64>` conversion fails despite the `Geometry::Polygon(_)` guard — e.g. polygons with empty exteriors or invalid ring data.","commonSituations":"Loading malformed polygons from external data; geo crate upgrades changing conversion semantics; corrupted geometry payloads.","solutions":["Validate polygon inputs (non-empty exterior ring) before aggregation.","Check geo crate version behavior of the Polygon TryFrom impl.","Replace expect with error propagation so invalid polygons produce a query error."],"exampleFix":"// before\n.map(|geo| geo.try_into().expect(\"polygon geometry\"))\n// after\n.map(|geo| geo.try_into().map_err(|e| ErrorCode::BadArguments(format!(\"polygon geometry: {e}\"))))\n.collect::<Result<Vec<_>, _>>()?;","handlingStrategy":"validation","validationCode":"// caller-side check before aggregating:\nlet all_valid_polygons = geos.iter().all(|g| matches!(g, Geometry::Polygon(p) if !p.exterior().coords().is_empty()));","typeGuard":"fn has_valid_exterior(g: &Geometry) -> bool { matches!(g, Geometry::Polygon(p) if p.exterior().coords().count() >= 4) }","tryCatchPattern":"let result = std::panic::catch_unwind(|| aggregate_polygons(geos.clone()));","preventionTips":["Validate polygon exteriors (non-empty ring) before running aggregates.","Check geo crate version compatibility for Polygon conversions.","Report any occurrence with reproducible input — it indicates a converter bug."],"tags":["rust","geospatial","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}