feat: make extension type wrappers fallible#261
Open
thomaschi78 wants to merge 2 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #260.
What this changes
GeoArrowExtensionTypeFactory::create_type_instanceis infallible by the Polars API contract, so whenGeoArrowType::from_extension_fieldfails (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 fromstruct PointType(T)tostruct PointType(Result<T, String>). Adds aninvalid(error)constructor and a privateformat_innerhelper (shared bydyn_displayanddyn_debugto avoid duplication).serialize_metadatareturnsNoneon error.name()always returns the correct constant regardless of validity. Replaces the infallibleFrom<WrapperType> for geoarrow_schema::TwithTryFrom.factory.rs— replaces.expect(...)with amatch; the error arm dispatches bynameto create the right wrapper type in invalid state.Tests (22 new)
Covers the valid and error paths for:
TryFromroundtrip and error message preservationFrominfallible constructorname()with valid and invalid inner valueserialize_metadatareturningNonein both casesdyn_display/dyn_debugoutput for valid and invalid typesCloneon invalid typesPartialEq— same-error equal, different-error unequal, valid ≠ invalid