Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not raise on unsuccessful cast #156

Merged
merged 5 commits into from
Apr 30, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/geo_postgis/geometry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,29 @@
def cast(%struct{} = geom) when struct in @geometries, do: {:ok, geom}

def cast(%{"type" => type, "coordinates" => _} = geom) when type in @types do
{:ok, Geo.JSON.decode!(geom)}
do_cast(geom)
end

def cast(%{"type" => "GeometryCollection", "geometries" => _} = geom) do
{:ok, Geo.JSON.decode!(geom)}
do_cast(geom)
end

def cast(geom) when is_binary(geom) do
{:ok, geom |> Geo.PostGIS.Config.json_library().decode!() |> Geo.JSON.decode!()}
do_cast(geom)
end

defp do_cast(geom) when is_binary(geom) do
case Geo.PostGIS.Config.json_library().decode(geom) do
{:ok, geom} when is_map(geom) -> do_cast(geom)
{:error, reason} -> {:error, [message: "failed to decode JSON", reason: reason]}
end
end

defp do_cast(geom) do
case Geo.JSON.decode(geom) do
{:ok, result} -> {:ok, result}
{:error, reason} -> {:error, [message: "failed to decode GeoJSON", reason: reason]}
end
end

def cast(_), do: :error
Expand All @@ -94,5 +108,5 @@
def embed_as(_), do: :self

def equal?(a, b), do: a == b
end

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Quality Checks

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.11.4, 24.3.4)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.12.3, 24.3.4)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.13.4, 24.3.4)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.13.4, 25.3.2)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.14.4, 24.3.4)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.14.4, 25.3.2)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.14.4, 26.0.2)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.15.5, 24.3.4)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.15.5, 25.3.2)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)

Check warning on line 111 in lib/geo_postgis/geometry.ex

View workflow job for this annotation

GitHub Actions / Elixir Unit Tests (1.15.5, 26.0.2)

clauses with the same name and arity (number of arguments) should be grouped together, "def cast/1" was previously defined (lib/geo_postgis/geometry.ex:81)
end
Loading