Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch and print out exceptions to standard error and never used exit code 1 #58

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/erlfmt_cli.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ opts() ->

-spec do(list(), string()) -> ok.
do(Opts, Name) ->
try do_unprotected(Opts, Name)
catch
Kind:Reason:Stack ->
io:format(standard_error, "~s Internal Error~n~s:~p~n~p~n", [Name, Kind, Reason, Stack]),
erlang:halt(127)
end.

-spec do_unprotected(list(), string()) -> ok.
do_unprotected(Opts, Name) ->
case parse_opts(Opts, Name, [], #config{}) of
{format, Files, Config} ->
case format_files(Files, Config, _HadErrors = false) of
Expand All @@ -46,7 +55,7 @@ do(Opts, Name) ->
{error, Message} ->
io:put_chars(standard_error, [Message, "\n\n"]),
getopt:usage(opts(), Name),
erlang:halt(1)
erlang:halt(2)
end.

format_files([FileName | FileNames], Config, HadErrors) ->
Expand Down