Skip to content

Commit 56a372c

Browse files
committed
Use file:consult to check if .conf is of the old format. Add more errors to the .config check
1 parent 61f7e9c commit 56a372c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/rabbit_config.erl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ assert_config(Filename, Env) ->
257257
case filelib:is_regular(Filename) of
258258
true ->
259259
case file:consult(Filename) of
260-
{ok, _} -> ok;
260+
{ok, []} -> {error, "ERROR: Config file ~s should not be empty: ~s"};
261+
{ok, [_]} -> ok;
262+
{ok, [_|_]} -> {error, "ERROR: Config file ~s must contain ONE list ended by <dot>: ~s"};
261263
{error, {1, erl_parse, Err}} ->
262264
{error, {"ERROR: Unable to parse erlang terms from ~s file: ~s~n"
263265
"ERROR: Reason: ~p~n"
@@ -283,8 +285,9 @@ assert_conf(Filename, Env) ->
283285
".conf" = filename:extension(Filename),
284286
case filelib:is_regular(Filename) of
285287
true ->
286-
case file:read_file(Filename) of
287-
{ok, <<"[", _/binary>>} ->
288+
case file:consult(Filename) of
289+
{ok, []} -> ok;
290+
{ok, _} ->
288291
{error, {"ERROR: Wrong format of the config file ~s: ~s~n"
289292
"ERROR: Check that the file is in the new ini-style config format "
290293
"If you are using the old format the file extension should "

0 commit comments

Comments
 (0)