fix: List.wrap geo_types in constraint error formatter#13
Conversation
`apply_constraint/2` accepts `geo_types` as either a bare atom or a
list (it `List.wrap`s before matching), but `constraint_error_geo_types/2`
calls `Enum.map_join(geo_types, ", ", &inspect/1)` on the raw value.
When a constraint is declared with the bare-atom form
(`constraints: [geo_types: :point]`, which the docs and the existing
test fixtures both use) and a non-matching Geo struct triggers the
error path, the formatter crashes:
** (Protocol.UndefinedError) protocol Enumerable not implemented
for type Atom. Got value: :point
`List.wrap/1` on the formatter's input makes both forms work.
Adds a regression test: Constraint.create_point/1 (declared with the
bare-atom `geo_types: :point`) given a non-Point Geo struct now returns
{:error, _} cleanly instead of raising.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes a bug in the constraint error message formatter that crashed when ChangesGeometry constraint error formatting
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@zachdaniel or @bcksl is ash_geo being actively maintained? |
Problem
apply_constraint/2accepts thegeo_typesconstraint as either a bare atom or a list — itList.wraps the value before matching:But the error formatter doesn't wrap:
So when a constraint is declared with the bare-atom form — which both the docs and the existing test fixture use:
…and a non-matching Geo struct hits the error path, the formatter raises:
The accept path works (the struct passes), so this only surfaces when validation fails with a bare-atom
geo_types.Fix
List.wrap/1the formatter's input so both the bare-atom and list forms render:Test
Adds a regression test under the existing "Argument constraints: geo_types: [:point]" describe block.
Constraint.create_point/1is declared withgeo_types: :point(bare atom); given a non-Point Geo struct (aLINESTRING), it now returns{:error, _}cleanly instead of raising in the formatter.Discovered while adopting AshGeo as the spatial type surface for ash_neo4j (a Neo4j
Ash.DataLayer). Happy to adjust to fit your preferences.Summary by CodeRabbit