2

After finally setting up my repo Cross DB Ecto config failing trying to run a query gives me this:

iex(1)> import Ecto.Query
Ecto.Query
iex(2)> Drupex.DrupalRepo.query(from "watchdog", select: [:wid]);
** (Protocol.UndefinedError) protocol String.Chars not implemented for #Ecto.Query<from w in "watchdog", select: [:wid]>. This protocol is implemented for: Atom, BitString, Date, DateTime, Decimal, Ecto.Date, Ecto.DateTime, Ecto.Time, Float, Integer, List, Mariaex.Query, NaiveDateTime, Postgrex.Copy, Postgrex.Query, Postgrex.Stream, Time, URI, Version, Version.Requirement
    (elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
    (elixir) lib/string/chars.ex:22: String.Chars.to_string/1
    (ecto) lib/ecto/adapters/sql.ex:613: Ecto.Adapters.SQL.log/4
    (db_connection) lib/db_connection.ex:1186: DBConnection.log/6
    (db_connection) lib/db_connection.ex:643: DBConnection.execute/4
    (ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6

I tried to Google on how to get the error handler to show arguments but found nothing so I do not know what the error is -- is my query invalid, does it have a problem connecting to the MySQL server etc.

Edit: I figured it out, it's Drupex.DrupalRepo.all. I figured it out by adding IO.inspect calls into lib/ecto/adapters/sql.ex but this is a very dirty hack, surely there are better ways.

chx
  • 11,270
  • 7
  • 55
  • 129
  • Using https://hexdocs.pm/ecto/Ecto.Adapters.SQL.html#to_sql/3 I was able to inspect the generated query. It helped me debug before. Maybe it could be of some use to you. – bla Apr 14 '18 at 01:14
  • Why don't you try Repo? – Jagdish Apr 18 '18 at 21:11
  • The question is about debugging practices like how to expand the stack trace to include arguments, to show the real error and so on. – chx Apr 19 '18 at 03:01

0 Answers0