solnic / drops

🛠️ Tools for working with data effectively - data contracts using types, schemas, domain validation rules, type-safe casting, and more.
Other
251 stars 4 forks source link

In Realease, ProtocolUndefinedError for Drops.Type.Validator and Drops.Types.Primitive #54

Closed djcoin closed 3 months ago

djcoin commented 3 months ago

Hi Solnic,

I'm posting this because I'm not sure if I did something wrong, on my local machine everything is fine, but on release, I get and error when calling :

Drops.Type.Validator.validate(Drops.Types.Primitive.new(:string), "")

Drops.Type.Validator.validate(Drops.Types.Primitive.new(:string), "")
** (Protocol.UndefinedError) protocol Drops.Type.Validator not implemented for %Drops.Types.Primitive{primitive: :string, constraints: [predicate: {:type?, [:string]}], opts: []} of type Drops.Types.Primitive (a struct). This protocol is implemented for the following type(s): Drops.Types.Cast, Drops.Types.List, Drops.Types.Map, Drops.Types.Map.Key, Drops.Types.Union, Kernel
    (drops 0.2.0) lib/drops/type/validator.ex:1: Drops.Type.Validator.impl_for!/1
    (drops 0.2.0) lib/drops/type/validator.ex:7: Drops.Type.Validator.validate/2
    iex:33: (file)

Maybe it's not related to your lib but related to the release mode and protocol. I don't know.

Cheers

djcoin commented 3 months ago

Update, so protocol are not consolidated in the same way:

On dev :

iex(16)> Drops.Type.Validator.__protocol__(:impls)
{:consolidated,
 [Drops.Types.Cast, Drops.Types.List, Drops.Types.Map, Drops.Types.Map.Key,
  Drops.Types.Number, Drops.Types.Primitive, Drops.Types.Union]}

and this in release mode

{:consolidated,
 [Drops.Types.Cast, Drops.Types.List, Drops.Types.Map, Drops.Types.Map.Key,
  Drops.Types.Union, Kernel]}
djcoin commented 3 months ago

Upgrading from Elixir 1.4 to 1.7 solved it! Nothing to do w/ your code I think but with how Elixir handles protocol consolidation , cheers ! 🎉