neurodynamic

neurodynamic

Unexpected error using message: {msg, opts} option in validation code

I’ve been trying to use the {msg, opts} tuple variant of the :message option in validate_format, taking a validation that looked like this:

|> validate_format(:field, ~r/some_regex/, message: "oh no!")

to this

|> validate_format(:field, ~r/some_regex/, message: {"oh no!", [error_type: :some_error_type]})

but when I do, I start to get errors that look like this in my validation code:

     ** (EXIT from #PID<0.2412.0>) an exception was raised:
     
          ** (FunctionClauseError) no function clause matching in anonymous fn/1 in Ecto.Changeset.validate_change/3

          The following arguments were given to anonymous fn/1 in Ecto.Changeset.validate_change/3:

              # 1
              {:field, {{"oh no!", [error_type: :some_error_type]}, [validation: :format]}}

          stacktrace:
            (ecto 3.11.2) lib/ecto/changeset.ex:2430: anonymous fn/1 in Ecto.Changeset.validate_change/3
            (elixir 1.16.2) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
            (ecto 3.11.2) lib/ecto/changeset.ex:2430: Ecto.Changeset.validate_change/3

Am I misunderstanding how the tuple variant for the :message option is supposed to look? I can’t figure out why this error is happening.

Marked As Solved

fuelen

fuelen

Update ecto :slight_smile: This option is available since v3.12.0

Last Post!

neurodynamic

neurodynamic

Ah! Thank you!

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement