Regex validation error

Getting this error when validating:
validate match(:code, "^[A-Za-z0-9]+$/")
validate match(:code, "^[A-Za-z0-9]+$/")
**Error**
protocol String.Chars not implemented for type Regex (a struct)

Got value:

~r/^[A-Za-z0-9]+$/
**Error**
protocol String.Chars not implemented for type Regex (a struct)

Got value:

~r/^[A-Za-z0-9]+$/
Any idea what's wrong?
13 Replies
ZachDaniel
ZachDaniel2mo ago
Huh...that's weird Can you set up a reproduction? That should work fine
Joan Gavelán
Joan GavelánOP2mo ago
Yes. I'll do it tomorrow as soon as possible
ken-kost
ken-kost2mo ago
what if you put ~r? 🤔
Joan Gavelán
Joan GavelánOP2mo ago
Same thing. That's actually what I tried initially, then read the docs and changed it to the string version, but the problem persisted
ZachDaniel
ZachDaniel2mo ago
Can you share the whole error including stack trace? (In general always do that)
Joan Gavelán
Joan GavelánOP2mo ago
# Protocol.UndefinedError at POST /inventario

Exception:

** (Protocol.UndefinedError) protocol String.Chars not implemented for type Regex (a struct)

Got value:

~r/^[A-Za-z0-9]+$/

(elixir 1.18.3) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir 1.18.3) lib/string/chars.ex:22: String.Chars.to_string/1
(ash_phoenix 2.3.14) lib/ash_phoenix/inertia/error.ex:120: anonymous fn/2 in AshPhoenix.Inertia.Error.default_message_func/1
(elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash_phoenix 2.3.14) lib/ash_phoenix/inertia/error.ex:107: anonymous fn/3 in AshPhoenix.Inertia.Error.to_errors/2
(elixir 1.18.3) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
(elixir 1.18.3) lib/enum.ex:4442: Enum.flat_map_list/2
(ash_phoenix 2.3.14) lib/ash_phoenix/inertia/error.ex:101: AshPhoenix.Inertia.Error.to_errors/2
(inertia 2.4.0) lib/inertia/controller.ex:254: Inertia.Controller.assign_errors/2
(lamashka 0.1.0) lib/lamashka_web/controllers/inventory_controller.ex:35: LamashkaWeb.InventoryController.create/2
(lamashka 0.1.0) lib/lamashka_web/controllers/inventory_controller.ex:1: LamashkaWeb.InventoryController.action/2
(lamashka 0.1.0) lib/lamashka_web/controllers/inventory_controller.ex:1: LamashkaWeb.InventoryController.phoenix_controller_pipeline/2
(phoenix 1.8.0) lib/phoenix/router.ex:416: Phoenix.Router.__call__/5
(lamashka 0.1.0) lib/lamashka_web/endpoint.ex:1: LamashkaWeb.Endpoint.plug_builder_call/2
(lamashka 0.1.0) deps/plug/lib/plug/debugger.ex:155: LamashkaWeb.Endpoint."call (overridable 3)"/2
(lamashka 0.1.0) lib/lamashka_web/endpoint.ex:1: LamashkaWeb.Endpoint.call/2
(phoenix 1.8.0) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
(bandit 1.8.0) lib/bandit/pipeline.ex:131:
# Protocol.UndefinedError at POST /inventario

Exception:

** (Protocol.UndefinedError) protocol String.Chars not implemented for type Regex (a struct)

Got value:

~r/^[A-Za-z0-9]+$/

(elixir 1.18.3) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir 1.18.3) lib/string/chars.ex:22: String.Chars.to_string/1
(ash_phoenix 2.3.14) lib/ash_phoenix/inertia/error.ex:120: anonymous fn/2 in AshPhoenix.Inertia.Error.default_message_func/1
(elixir 1.18.3) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash_phoenix 2.3.14) lib/ash_phoenix/inertia/error.ex:107: anonymous fn/3 in AshPhoenix.Inertia.Error.to_errors/2
(elixir 1.18.3) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
(elixir 1.18.3) lib/enum.ex:4442: Enum.flat_map_list/2
(ash_phoenix 2.3.14) lib/ash_phoenix/inertia/error.ex:101: AshPhoenix.Inertia.Error.to_errors/2
(inertia 2.4.0) lib/inertia/controller.ex:254: Inertia.Controller.assign_errors/2
(lamashka 0.1.0) lib/lamashka_web/controllers/inventory_controller.ex:35: LamashkaWeb.InventoryController.create/2
(lamashka 0.1.0) lib/lamashka_web/controllers/inventory_controller.ex:1: LamashkaWeb.InventoryController.action/2
(lamashka 0.1.0) lib/lamashka_web/controllers/inventory_controller.ex:1: LamashkaWeb.InventoryController.phoenix_controller_pipeline/2
(phoenix 1.8.0) lib/phoenix/router.ex:416: Phoenix.Router.__call__/5
(lamashka 0.1.0) lib/lamashka_web/endpoint.ex:1: LamashkaWeb.Endpoint.plug_builder_call/2
(lamashka 0.1.0) deps/plug/lib/plug/debugger.ex:155: LamashkaWeb.Endpoint."call (overridable 3)"/2
(lamashka 0.1.0) lib/lamashka_web/endpoint.ex:1: LamashkaWeb.Endpoint.call/2
(phoenix 1.8.0) lib/phoenix/endpoint/sync_code_reload_plug.ex:22: Phoenix.Endpoint.SyncCodeReloadPlug.do_call/4
(bandit 1.8.0) lib/bandit/pipeline.ex:131:
Bandit.Pipeline.call_plug!/2
(bandit 1.8.0) lib/bandit/pipeline.ex:42: Bandit.Pipeline.run/5
(bandit 1.8.0) lib/bandit/http2/stream_process.ex:28: Bandit.HTTP2.StreamProcess.handle_continue/2


## Connection details

### Params

%{"barcode" => "", "category_id" => nil, "code" => "1NDD4Q8K@", "image" => "", "name" => "Nombre", "tracks_inventory" => true, "type" => "product", "unit_of_measure" => "NIU"}

### Request info

* URI: https://app.lamashka.dev:443/inventario
* Query string:

### Session

%{"_csrf_token" => "eaR9Rz9RvgYt8pDYBgmJhH0R", "establishment_id" => "0198e55b-55bd-7e4f-aa3a-b71d5330a0d5", "session_params" => %{state: "stDaJZEBpo139vKZrtonL3N3zqUU9jIA"}, "user_token" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ-PiA0LjkiLCJleHAiOjE3NTc3ODc4MjEsImlhdCI6MTc1NjU3ODIyMSwiaXNzIjoiQXNoQXV0aGVudGljYXRpb24gdjQuOS45IiwianRpIjoiMzFnOXQ1ZzhnNDY1bHY3OThnMDAwM2szIiwibmJmIjoxNzU2NTc4MjIxLCJwdXJwb3NlIjoidXNlciIsInN1YiI6InVzZXI_aWQ9MDE5OGU1NWEtZjMzNS03NWVkLWIzYzUtNjgyNDRhNGNlN2EwIn0.-0wRRqWgjzW4VnCpQM5rbBPqQoxTHhRRAab8wv286r4"}
Bandit.Pipeline.call_plug!/2
(bandit 1.8.0) lib/bandit/pipeline.ex:42: Bandit.Pipeline.run/5
(bandit 1.8.0) lib/bandit/http2/stream_process.ex:28: Bandit.HTTP2.StreamProcess.handle_continue/2


## Connection details

### Params

%{"barcode" => "", "category_id" => nil, "code" => "1NDD4Q8K@", "image" => "", "name" => "Nombre", "tracks_inventory" => true, "type" => "product", "unit_of_measure" => "NIU"}

### Request info

* URI: https://app.lamashka.dev:443/inventario
* Query string:

### Session

%{"_csrf_token" => "eaR9Rz9RvgYt8pDYBgmJhH0R", "establishment_id" => "0198e55b-55bd-7e4f-aa3a-b71d5330a0d5", "session_params" => %{state: "stDaJZEBpo139vKZrtonL3N3zqUU9jIA"}, "user_token" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ-PiA0LjkiLCJleHAiOjE3NTc3ODc4MjEsImlhdCI6MTc1NjU3ODIyMSwiaXNzIjoiQXNoQXV0aGVudGljYXRpb24gdjQuOS45IiwianRpIjoiMzFnOXQ1ZzhnNDY1bHY3OThnMDAwM2szIiwibmJmIjoxNzU2NTc4MjIxLCJwdXJwb3NlIjoidXNlciIsInN1YiI6InVzZXI_aWQ9MDE5OGU1NWEtZjMzNS03NWVkLWIzYzUtNjgyNDRhNGNlN2EwIn0.-0wRRqWgjzW4VnCpQM5rbBPqQoxTHhRRAab8wv286r4"}
ZachDaniel
ZachDaniel2mo ago
Okay that's likely a bug in ash_phoenix
Joan Gavelán
Joan GavelánOP2mo ago
No description
ZachDaniel
ZachDaniel2mo ago
Yeah Make sure you're on the latest version also If that doesn't work please open an issue
Joan Gavelán
Joan GavelánOP2mo ago
Alright I think this has to do with how AshPhoenix is formatting the errors for Inertia right? Yes I'm on the latest version
ZachDaniel
ZachDaniel2mo ago
Kk, then yeah we'll want to look at how that protocol is implemented and likely check for regex values in vars for example
Joan Gavelán
Joan GavelánOP2mo ago
GitHub
Protocol.UndefinedError when using Regex in validation with AshPhoe...
Code of Conduct I agree to follow this project's Code of Conduct AI Policy I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue. Versions Er...
Joan Gavelán
Joan GavelánOP2mo ago
Done Let me know if there is something else I can do

Did you find this page helpful?