elixir-sqlite/sqlite_ecto2

Error with IO.chardata_to_string/1 creating database

jfcalvo opened this issue · 5 comments

I'm getting the following error executing mix ecto.create with a phoenix project:

===> Fetching pc ({pkg,<<"pc">>,<<"1.6.0">>})
===> Downloaded package, caching at /Users/jfcalvo/.cache/rebar3/hex/default/packages/pc-1.6.0.tar
===> Compiling pc
===> Compiling esqlite
===> Compiling /Users/jfcalvo/Projects/futon/deps/esqlite/c_src/esqlite3_nif.c
===> Compiling /Users/jfcalvo/Projects/futon/deps/esqlite/c_src/queue.c
===> Compiling /Users/jfcalvo/Projects/futon/deps/esqlite/c_src/sqlite3.c
===> Linking /Users/jfcalvo/Projects/futon/deps/esqlite/priv/esqlite3_nif.so
===> Compiling sbroker
==> db_connection
Compiling 23 files (.ex)
Generated db_connection app
==> ecto
Compiling 70 files (.ex)
Generated ecto app
==> sqlitex
Compiling 8 files (.ex)
Generated sqlitex app
==> sqlite_ecto2
Compiling 8 files (.ex)
Generated sqlite_ecto2 app
==> phoenix_ecto
Compiling 4 files (.ex)
Generated phoenix_ecto app
==> futon
Compiling 13 files (.ex)
Generated futon app
** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1

    The following arguments were given to IO.chardata_to_string/1:

        # 1
        nil

    Attempted function clauses (showing 2 out of 2):

        def chardata_to_string(string) when is_binary(string)
        def chardata_to_string(list) when is_list(list)

    (elixir) lib/io.ex:445: IO.chardata_to_string/1
    (elixir) lib/file.ex:153: File.exists?/1
    lib/sqlite_ecto.ex:109: Sqlite.Ecto2.storage_up/1
    lib/mix/tasks/ecto.create.ex:40: anonymous fn/3 in Mix.Tasks.Ecto.Create.run/1
    (elixir) lib/enum.ex:675: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:675: Enum.each/2
    (mix) lib/mix/task.ex:301: Mix.Task.run_task/3
    (mix) lib/mix/cli.ex:75: Mix.CLI.run_task/2
    (elixir) lib/code.ex:376: Code.require_file/2

I'm using Elixir 1.5.1 and Phoenix 1.3.0 my dependencies are the following:

  defp deps do
    [
      {:phoenix, "~> 1.3.0"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_ecto, "~> 3.2"},
      {:sqlite_ecto2, "~> 2.2"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_live_reload, "~> 1.0", only: :dev},
      {:gettext, "~> 0.11"},
      {:cowboy, "~> 1.0"}
    ]
  end

Looks like some problem with sqlite_ecto2 but I don't know if I'm doing something wrong.

Any help is welcome.

After add a database path to the Repo config the mix ecto.create command is working as expected:

config :futon, Futon.Repo,
  adapter: Sqlite.Ecto2,
  database: "test"

In my own opinion a default database path should be defined if none is provided in the config because with that error is very difficult to know what is happening.

Or maybe show a message like You need to define a database path.

@jfcalvo sorry for the confusion you encountered. I agree that this should change. I would welcome a PR that provides either a better error message or a default path (perhaps ":memory:"?). If you prefer not to, LMK and I'll work on an update as I have time. Thanks!

@jfcalvo heads up that I've been finding Travis CI rather fussy lately so don't be alarmed if you get a validation failure on PR submission. (Typical failure is a "killed" message when running mix dogma, which I think is a timeout.) I'll read the build log closely and resubmit if that's the issue.

@jfcalvo please see 2.2.2 release which now includes a better error message for this situation. Thanks again for pointing out the problem to me!

@scouten thanks to you for the improvement! 🎉