Skip to content

Commit e0eaae0

Browse files
committed
Fix a potential badmatch error
You can get `badmatch` if you run the broker with arguments like this: ``` make RABBITMQ_ALLOW_INPUT=true RABBITMQ_ADVANCED_CONFIG_FILE=/Users/lbakken/issues/pt/159000315-conf-format-check/test3/rabbitmq.conf RABBITMQ_CONFIG_FILE=/Users/lbakken/issues/pt/159000315-conf-format-check/test3/advanced.config run-broke ``` With this change, the following message is printed: ``` ERROR: RABBITMQ_ADVANCED_CONFIG_FILE: Expected extension .config, got extension .conf for file /Users/lbakken/issues/pt/159000315-conf-format-check/test3/rabbitmq.conf ```
1 parent b21eacf commit e0eaae0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/rabbit_config.erl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ validate_config_files() ->
253253
assert_config("", _) -> ok;
254254
assert_config(none, _) -> ok;
255255
assert_config(Filename, Env) ->
256-
".config" = filename:extension(Filename),
256+
assert_config(filename:extension(Filename), Filename, Env).
257+
258+
assert_config(".config", Filename, Env) ->
257259
case filelib:is_regular(Filename) of
258260
true ->
259261
case file:consult(Filename) of
@@ -282,11 +284,15 @@ assert_config(Filename, Env) ->
282284
end;
283285
false ->
284286
ok
285-
end.
287+
end;
288+
assert_config(BadExt, Filename, Env) ->
289+
{error, {"ERROR: '~s': Expected extension '.config', got extension '~s' for file '~s'~n", [Env, BadExt, Filename]}}.
286290

287291
assert_conf("", _) -> ok;
288292
assert_conf(Filename, Env) ->
289-
".conf" = filename:extension(Filename),
293+
assert_conf(filename:extension(Filename), Filename, Env).
294+
295+
assert_conf(".conf", Filename, Env) ->
290296
case filelib:is_regular(Filename) of
291297
true ->
292298
case file:consult(Filename) of
@@ -302,5 +308,6 @@ assert_conf(Filename, Env) ->
302308
end;
303309
false ->
304310
ok
305-
end.
306-
311+
end;
312+
assert_conf(BadExt, Filename, Env) ->
313+
{error, {"ERROR: '~s': Expected extension '.config', got extension '~s' for file '~s'~n", [Env, BadExt, Filename]}}.

0 commit comments

Comments
 (0)