Skip to content

Commit a032647

Browse files
authored
Fix mongo.drop task and add error handling (#153)
Thanks for the PR and for the very detailed explanation. Yes, you are right: the error handling was completely missing.
1 parent cfc968b commit a032647

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/mongo/migration.ex

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,31 @@ defmodule Mongo.Migration do
7878
_other ->
7979
:noop
8080
end
81+
rescue
82+
e ->
83+
IO.puts("🚨 Error when migrating #{mod}:")
84+
IO.puts(Exception.format(:error, e, __STACKTRACE__))
85+
reraise e, __STACKTRACE__
8186
end
8287

8388
defp run_down(version, mod) do
8489
topology = get_config()[:topology]
8590
collection = get_config()[:collection]
8691

8792
case Mongo.find_one(topology, collection, %{version: version}) do
88-
%{version: _version} ->
93+
%{"version" => _version} ->
8994
mod.down()
9095
Mongo.delete_one(topology, collection, %{version: version})
9196
IO.puts("💥 Successfully dropped #{mod}")
9297

9398
_other ->
9499
:noop
95100
end
101+
rescue
102+
e ->
103+
IO.puts("🚨 Error when dropping #{mod}:")
104+
IO.puts(Exception.format(:error, e, __STACKTRACE__))
105+
reraise e, __STACKTRACE__
96106
end
97107

98108
def get_config() do

0 commit comments

Comments
 (0)