From 58fa1ebcdfd26dfdacb8385a03177564c8f7100b Mon Sep 17 00:00:00 2001 From: David Szkiba Date: Tue, 22 Nov 2022 18:51:10 +0100 Subject: [PATCH] Show error if migration can not be created With this change, instead of failing silently, the user gets feedback if the migration file could not be created. --- src/psql_migration.erl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/psql_migration.erl b/src/psql_migration.erl index 0e03c77..90dbd8c 100644 --- a/src/psql_migration.erl +++ b/src/psql_migration.erl @@ -65,8 +65,12 @@ handle_command({ok, {Args, ["new", Name]}}) -> "-- :down\n", "-- Down migration\n" ], - file:write_file(Filename, list_to_binary(C), [exclusive]), - handle_command_result({ok, "Created migration: ~s~n", [Filename]}); + Result = case file:write_file(Filename, list_to_binary(C), [exclusive]) of + ok -> {ok, "Created migration: ~s~n", [Filename]}; + {error, Reason} -> {error, + "Migration can not be written to file ~s: ~s~n", [Filename, Reason]} + end, + handle_command_result(Result); handle_command({ok, {Args, ["run"]}}) -> Available = available_migrations(Args), Result = with_connection(