kipcole9 / money_sql

Money functions for the serialization of a money data type in Elixir
Other
27 stars 18 forks source link

Ecto types return malformed error when casting invalid currency #4

Closed bgracie closed 4 years ago

bgracie commented 4 years ago

When casting an invalid currency, the both ecto types return an error tuple with another tuple as the second element.

https://github.com/kipcole9/money_sql/blob/bbc4f69b0152cb052c945fa17c51417103dc0b4b/test/money_ecto_test.exs#L72

This violates the typespec for Ecto.Type.cast: cast(term()) :: {:ok, term()} | {:error, keyword()} | :error, and causes an exception when used in Ecto.Changeset.cast

Please see this demo repo for a demonstration of the issue.

Incidentally, it appears that the load functions also violate the error typespec from Ecto.Type.

kipcole9 commented 4 years ago

@bgracie I apologise, I only just noticed this (I need to check notifications on this repo). I’ll fix this right away.

bgracie commented 4 years ago

@kipcole9 Thanks!