Shenrak
Hi everyone,
I am trying to use Ecto.insert, and i have the following error :
[error] #PID<0.416.0> running GORprojectWeb.Endpoint (cowboy_protocol) terminated
Server: localhost:4000 (http)
Request: POST /api/rooms
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in GORprojectWeb.ErrorHelpers.translate_error/1
(gor_project) lib/gor_project_web/views/error_helpers.ex:9: GORprojectWeb.ErrorHelpers.translate_error("is invalid")
(ecto) lib/ecto/changeset.ex:2345: anonymous fn/3 in Ecto.Changeset.merge_error_keys/3
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto) lib/ecto/changeset.ex:2339: Ecto.Changeset.traverse_errors/2
(gor_project) lib/gor_project_web/views/changeset_view.ex:17: GORprojectWeb.ChangesetView.render/2
(phoenix) lib/phoenix/view.ex:332: Phoenix.View.render_to_iodata/3
(phoenix) lib/phoenix/controller.ex:740: Phoenix.Controller.do_render/4
(gor_project) lib/gor_project_web/controllers/room_controller.ex:1: GORprojectWeb.RoomController.action/2
(gor_project) lib/gor_project_web/controllers/room_controller.ex:1: GORprojectWeb.RoomController.phoenix_controller_pipeline/2
(gor_project) lib/gor_project_web/endpoint.ex:1: GORprojectWeb.Endpoint.instrument/4
(phoenix) lib/phoenix/router.ex:278: Phoenix.Router.__call__/1
(gor_project) lib/gor_project_web/endpoint.ex:1: GORprojectWeb.Endpoint.plug_builder_call/2
(gor_project) lib/gor_project_web/endpoint.ex:1: GORprojectWeb.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:16: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) /Users/giom/Documents/develop/web/GORProject-API/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
After some investigations, it seems that the error comes from an association not loaded, but the errors kind of triggers me because i have in my errors.pot the strings to handle this error :
## From Ecto.Changeset.put_change/3
msgid "is invalid"
msgstr ""
So i should be handled.
Here are my schemas, CRUD and controller :
Schema :
defmodule GORproject.Rooms.Room do
use Ecto.Schema
import Ecto.Changeset
alias GORproject.Rooms.Room
alias GORproject.Auth.User
schema "rooms" do
field(:depth, :integer)
field(:name, :string)
field(:description, :string)
field(:public, :boolean)
many_to_many(:users, User, join_through: "users_rooms")
has_many(:children, Room)
belongs_to(:father, Room, foreign_key: :father_id)
timestamps()
end
@doc false
def changeset(room, attrs) do
room
|> cast(attrs, [:name, :depth, :description, :public, :father_id])
|> foreign_key_constraint(:father_id)
|> validate_required([:name, :depth, :public])
end
end
CRUD :
def create_room(attrs \\ %{}) do
%Room{children: [], father: {}, users: []}
|> Room.changeset(attrs)
|> Repo.insert()
end
Controller :
def create(conn, %{"room" => room_params}) do
with {:ok, %Room{} = room} <- Rooms.create_room(room_params) do
conn
|> put_status(:created)
|> put_resp_header("location", room_path(conn, :create, room))
|> render("show.json", room: room)
end
end
Thank you ![]()
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Latest Phoenix Threads
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
script
How you handling in create method if changeset is not valid?
Shenrak
error is sent to my fallbackController :
script
Fall back controller is okay but its better if you use the error_view file for displaying changeset errors.
you can pass your invalid changeset to this and it will display an error from that changeset .
Shenrak
I added your code in my error_view.ex, and it seems like the error is not handled there. From the stacktrace it seems that it goes from room_controller directly to changeset_view, in which there is :
script
From stacktrace it seems like in
error helpersthe translate_error function is not working for youris invalidmessage. You are passing one argument but it accepts 2 arguments.Shenrak
I totally agree with you, and this is where i do not understand. In my
errors.pot, i have the following code :According to this thread, it should be working
script
what is your goal? What you trying to implement?
Shenrak
I am trying to understand why this error is raised, how to handle it properly, and of course i am trying to fix the Repo.insert error
note that the error is not raised anymore if i delete
father: {}insideBut i then have the following error :
script
Add
IO.inspectafter|> Room.changeset(attrs)And see what it gives you in the console. After you run this method
Shenrak
i’ve put two IO.inspect :
and i have :
followed by the error stacktrace