Skip to content

Commit 35d6421

Browse files
authored
Better error message if no database path provided. (#201)
* Better error message if no database path provided. Fixes #200. Thanks for the report, @jfcalvo. * Prepare 2.2.2 release.
1 parent 913b20d commit 35d6421

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog for v2.2.x Series
22

3+
## v2.2.2
4+
5+
_8 October 2017_
6+
7+
* Better error message if no database path provided. Fixes #200.
8+
9+
310
## v2.2.1
411

512
_11 September 2017_

lib/sqlite_ecto.ex

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,27 @@ defmodule Sqlite.Ecto2 do
105105

106106
@doc false
107107
def storage_up(opts) do
108-
database = Keyword.get(opts, :database)
108+
storage_up_with_path(Keyword.get(opts, :database), opts)
109+
end
110+
111+
defp storage_up_with_path(nil, opts) do
112+
raise ArgumentError,
113+
"""
114+
No SQLite database path specified. Please check the configuration for your Repo.
115+
Your config/*.exs file should have something like this in it:
116+
117+
config :my_app, MyApp.Repo,
118+
adapter: Sqlite.Ecto2,
119+
database: "/path/to/sqlite/database"
120+
121+
Options provided were:
122+
123+
#{inspect opts, pretty: true}
124+
125+
"""
126+
end
127+
128+
defp storage_up_with_path(database, _opts) do
109129
if File.exists?(database) do
110130
{:error, :already_up}
111131
else

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule Sqlite.Ecto2.Mixfile do
33

44
def project do
55
[app: :sqlite_ecto2,
6-
version: "2.2.1",
6+
version: "2.2.2",
77
name: "Sqlite.Ecto2",
88
elixir: "~> 1.4",
99
elixirc_options: [warnings_as_errors: true],

mix.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [:mix], [], "hexpm"},
88
"dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
99
"earmark": {:hex, :earmark, "1.2.2", "f718159d6b65068e8daeef709ccddae5f7fdc770707d82e7d126f584cd925b74", [:mix], [], "hexpm"},
10-
"ecto": {:hex, :ecto, "2.2.2", "e9bd6ebc044eaaab1cb369e3465686d8aca830aa5bf545ef2bae000a3d42c54b", [], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
10+
"ecto": {:hex, :ecto, "2.2.2", "e9bd6ebc044eaaab1cb369e3465686d8aca830aa5bf545ef2bae000a3d42c54b", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
1111
"esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"},
1212
"ex_doc": {:hex, :ex_doc, "0.16.3", "cd2a4cfe5d26e37502d3ec776702c72efa1adfa24ed9ce723bb565f4c30bd31a", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
1313
"hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "4.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},

test/sqlite_ecto_test.exs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,32 @@ defmodule Sqlite.Ecto2.Test do
1212

1313
import Ecto.Query
1414

15-
test "storage up (twice)" do
16-
tmp = [database: tempfilename()]
17-
assert Sqlite.Ecto2.storage_up(tmp) == :ok
18-
assert File.exists? tmp[:database]
19-
assert Sqlite.Ecto2.storage_up(tmp) == {:error, :already_up}
20-
File.rm(tmp[:database])
15+
describe "storage_up" do
16+
test "fails with :already_up on second call" do
17+
tmp = [database: tempfilename()]
18+
assert Sqlite.Ecto2.storage_up(tmp) == :ok
19+
assert File.exists? tmp[:database]
20+
assert Sqlite.Ecto2.storage_up(tmp) == {:error, :already_up}
21+
File.rm(tmp[:database])
22+
end
23+
24+
test "fails with helpful error message if no database specified" do
25+
assert_raise ArgumentError,
26+
"""
27+
No SQLite database path specified. Please check the configuration for your Repo.
28+
Your config/*.exs file should have something like this in it:
29+
30+
config :my_app, MyApp.Repo,
31+
adapter: Sqlite.Ecto2,
32+
database: "/path/to/sqlite/database"
33+
34+
Options provided were:
35+
36+
[mumble: "no database here"]
37+
38+
""",
39+
fn -> Sqlite.Ecto2.storage_up([mumble: "no database here"]) == :ok end
40+
end
2141
end
2242

2343
test "storage down (twice)" do

0 commit comments

Comments
 (0)