Skip to content

feat: make extension type wrappers fallible#261

Open
thomaschi78 wants to merge 2 commits into
pola-rs:mainfrom
thomaschi78:feat/fallible-extension-types
Open

feat: make extension type wrappers fallible#261
thomaschi78 wants to merge 2 commits into
pola-rs:mainfrom
thomaschi78:feat/fallible-extension-types

Conversation

@thomaschi78

Copy link
Copy Markdown

Closes #260.

What this changes

GeoArrowExtensionTypeFactory::create_type_instance is infallible by the Polars API contract, so when GeoArrowType::from_extension_field fails (incompatible storage type for the named extension), the factory was panicking via .expect(...).

This PR stores the error inside the wrapper type instead of panicking:

  • geoarrow.rs — changes the macro-generated structs from struct PointType(T) to struct PointType(Result<T, String>). Adds an invalid(error) constructor and a private format_inner helper (shared by dyn_display and dyn_debug to avoid duplication). serialize_metadata returns None on error. name() always returns the correct constant regardless of validity. Replaces the infallible From<WrapperType> for geoarrow_schema::T with TryFrom.

  • factory.rs — replaces .expect(...) with a match; the error arm dispatches by name to create the right wrapper type in invalid state.

Tests (22 new)

Covers the valid and error paths for:

  • TryFrom roundtrip and error message preservation
  • From infallible constructor
  • name() with valid and invalid inner value
  • serialize_metadata returning None in both cases
  • dyn_display / dyn_debug output for valid and invalid types
  • Clone on invalid types
  • PartialEq — same-error equal, different-error unequal, valid ≠ invalid
  • Factory happy path (valid storage → valid state)
  • Factory error path (incompatible storage → invalid state, no panic, correct name)

Store `Result<T, String>` instead of `T` in each GeoArrow wrapper type so
that an incompatible storage type passed to `GeoArrowExtensionTypeFactory`
is captured as an error rather than causing a panic. The `invalid()`
constructor and `TryFrom` conversion surface the error to callers; `name()`
always returns the correct constant regardless of validity.

Replaces the infallible `From<WrapperType> for geoarrow_schema::T` with
`TryFrom`, extracts a shared `format_inner` helper in the macro to avoid
duplicating `dyn_display`/`dyn_debug` logic, and adds 22 tests covering
the valid and error paths across constructors, traits, and the factory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow extension types to be fallible

1 participant