I’m new and just learning Phoenix. It seems to me there’s a lot of stuff happening"behind the curtain", and I have no idea how I’m supposed to debug it.
My app is crashing. There are two lines in the middle of the stack trace that reference my code. They both point at the same line, the defmodule in one of my controllers. After the line number, the first has my-controller-name.action/2. The second my-controller-name.phoenix_controller_pipeline/2.
Checking the source. Checking your tests. Adding in some pry's or inspect's. Posting the complete stacktrace at the forums here (^.^) or even a minimal reproduceable project. Etc…
Hard to give some precise debugging tips until we see what the stacktrace is, and maybe the code.
I’m working thru “Programming Elixir” 2016. It’s supposed to gracefully handle the case when the user tries to create a duplicate user. Instead it crashes.
Here’s the source file referenced in the stack trace.
defmodule Rumbl.UserController do
use Rumbl.Web, :controller
plug :authenticate_user when action in [:index, :show]
alias Rumbl.User
def new(conn, _params) do
changeset = User.changeset(%User{})
render conn, "new.html", changeset: changeset
end
def index(conn, _params) do
users = Repo.all(Rumbl.User)
render conn, "index.html", users: users
end
def show(conn, %{"id" => id}) do
user = Repo.get(Rumbl.User, id)
render conn, "show.html", user: user
end
def create(conn, %{"user" => user_params}) do
changeset = User.registration_changeset(%User{}, user_params)
case Repo.insert(changeset) do
{:ok, user} ->
conn
|> Rumbl.Auth.login(user)
|> put_flash(:info, "#{user.name} created!")
|> redirect(to: user_path(conn, :index))
{:error, changeset} ->
render("new.html", changeset: changeset)
end
end
end
And private is a thing on conn that is used by phoenix a lot, and checking your code where render was called you have:
render("new.html", changeset: changeset)
Which takes conn in the first position, but instead you passed in "new.html" in the first position, so it was trying to call .private on that instead of the conn map.
Phoenix should probably add a matcher on %Plug.Conn{} on those calls, the error message would be more obvious. PR it?