So, maybe this is a really simple issue that I'm missing, but I've setup my repo as follows and then execute a request as follows:
defmodule Weather.Repo do
use Ecto.Repo, adapter: Ecto.Adapters.Postgres
def url, do: "ecto://postgres:postgres@localhost/weather"
def priv, do: app_dir(:weather, "priv/repo")
end
Repo command:
iex(2)> query = from c in Weather.City, select: c.name
Ecto.Query.Query[sources: nil,
from: {"cities", Weather.City.Entity, Weather.City}, joins: [], wheres: [],
select: Ecto.Query.QueryExpr[expr: {{:., [], [{:&, [], [0]}, :name]}, [], []},
file: "iex", line: 2], order_bys: [], limit: nil, offset: nil, group_bys: [],
havings: [], preloads: [], distincts: []]
iex(3)> Weather.Repo.all query
** (exit) {:noproc, {:gen_server, :call, [Weather.Repo.Pool, {:checkout, true}, 5000]}}
:erlang.send(Weather.Repo.Pool, {:"$gen_cast", {:cancel_waiting, #PID<0.159.0>}}, [:noconnect])
(stdlib) gen_server.erl:399: :gen_server.do_send/2
(stdlib) gen_server.erl:208: :gen_server.do_cast/2
src/poolboy.erl:39: :poolboy.checkout/3
lib/ecto/adapters/postgres.ex:236: Ecto.Adapters.Postgres.use_worker/2
lib/ecto/adapters/postgres.ex:47: Ecto.Adapters.Postgres.all/2
It seems to be connecting to the postgres db because it complained once and I got passed that error, but this issue prohibits me from creating or querying anything. Any thoughts?
The repository was not started. Try Weather.Repo.start_link before querying.
@ericmj any ideas on how we could improve this error message? We could wrap all poolboy calls but this seems rather expensive. :(
@josevalim We could call Process.alive? on the pool name or catch the :noproc error. I don't know about the performance of either solution though.
Wow. Thanks so much @josevalim. Also, where would be the best place to put Weather.Repo.start_link?
I was reading the docs and it looks like if I add my repo to supervisor.ex in the init([]) function, it should go through to the repo and call start_link, but it apparently isn't working properly.
@rcdilorenzo I think the README goes in detail over that. Check the part about the supervisors (i.e. in your supervision tree).
I am closing this with "won't fix". A :no_proc error will hit the erlang/elixir programmer sooner or later because it is not common to check gen_server calls with Process.alive? before calling. It also seems to be easy to google.
Maybe an elixir abstraction of gen_server, which is planned, could make the errors nicer?
Maybe we should open an Elixir bug that handles :no_proc error and show them nicely formatted?
Most helpful comment
The repository was not started. Try
Weather.Repo.start_linkbefore querying.@ericmj any ideas on how we could improve this error message? We could wrap all poolboy calls but this seems rather expensive. :(