With else clause

I have a function of the form:

def authenticate(params) do
    with %User{} = user <- Users.get_user_by!(params) do
      {:ok, user}
    else
      _ -> :error
    end
  end

However, when there is an error, the else part never executes (even when I put IO.puts(“error”)), am I doing something wrong?

Going by the naming get_user_by! is throwing a runtime error. That is not what with was designed for. with deals with returned error values.

Or more generally:

Used to combine matching clauses.

Kernel.with/1

2 Likes

Oh I see, Thanks!