{"record":{"id":"a39edf5653bcacb6","repo":"databendlabs/databend","slug":"linestring-geometry","errorCode":null,"errorMessage":"linestring geometry","messagePattern":"linestring geometry","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/expression/src/geographic/aggregate.rs","lineNumber":104,"sourceCode":"        if geos.is_empty() {\n            return Ok(None);\n        }\n\n        if geos.iter().all(|geo| matches!(geo, Geometry::Point(_))) {\n            let points: Vec<Point<f64>> = geos\n                .into_iter()\n                .map(|geo| geo.try_into().expect(\"point geometry\"))\n                .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>>> {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/expression/src/geographic/aggregate.rs#L86-L122","documentation":"Same pattern as the point aggregate: in geographic aggregate `compute`, when all input geometries are `Geometry::LineString(_)`, each is converted to `LineString<f64>` via `try_into().expect(\"linestring geometry\")`. The preceding `matches!` guard should guarantee success, so the panic signals a broken conversion impl or malformed linestring data. It's an internal assertion guarding the all-LineString fast path that builds a MultiLineString.","triggerScenarios":"Aggregating LineString geometries where the `TryFrom<Geometry> for LineString<f64>` conversion unexpectedly fails despite the type guard — e.g. linestrings with fewer than required coordinates or invalid interior data.","commonSituations":"Ingesting degenerate linestrings (zero points) from external geometry sources; geo crate version drift changing conversion acceptance; corrupted serialized geometries.","solutions":["Check linestring inputs for degenerate/empty coordinate lists that the converter rejects.","Confirm the geo crate TryFrom impl matches the library's expected behavior for the version in use.","Convert the expect to a propagated error so bad data surfaces as a query error instead of a panic."],"exampleFix":"// before\n.map(|geo| geo.try_into().expect(\"linestring geometry\"))\n// after\n.map(|geo| geo.try_into().map_err(|e| ErrorCode::BadArguments(format!(\"linestring geometry: {e}\"))))\n.collect::<Result<Vec<_>, _>>()?;","handlingStrategy":"validation","validationCode":"// caller-side check before aggregating:\nlet all_valid_lines = geos.iter().all(|g| matches!(g, Geometry::LineString(l) if !l.coords().is_empty()));","typeGuard":"fn is_nonempty_linestring(g: &Geometry) -> bool { matches!(g, Geometry::LineString(l) if l.coords().count() > 0) }","tryCatchPattern":"let result = std::panic::catch_unwind(|| aggregate_linestrings(geos.clone()));","preventionTips":["Reject linestrings with zero coordinates at ingestion time.","Validate geometry payloads after deserialization.","Keep the geo crate version tested against the library."],"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"}