diff --git a/apps/emqx_conf/src/emqx_conf_cli.erl b/apps/emqx_conf/src/emqx_conf_cli.erl index e730f23c0..8c38d74bc 100644 --- a/apps/emqx_conf/src/emqx_conf_cli.erl +++ b/apps/emqx_conf/src/emqx_conf_cli.erl @@ -312,8 +312,14 @@ get_config(Key) -> load_config(Path, Opts) when is_list(Path) -> case hocon:files([Path]) of {ok, RawConf} when RawConf =:= #{} -> - emqx_ctl:warning("load ~ts is empty~n", [Path]), - {error, empty_hocon_file}; + case filelib:is_file(Path) of + true -> + emqx_ctl:warning("load ~ts is empty~n", [Path]), + {error, empty_hocon_file}; + false -> + emqx_ctl:warning("~ts is not found~n", [Path]), + {error, not_found_hocon_file} + end; {ok, RawConf} -> load_config_from_raw(RawConf, Opts); {error, Reason} -> diff --git a/apps/emqx_conf/test/emqx_conf_cli_SUITE.erl b/apps/emqx_conf/test/emqx_conf_cli_SUITE.erl index 63f6821b8..f345e6238 100644 --- a/apps/emqx_conf/test/emqx_conf_cli_SUITE.erl +++ b/apps/emqx_conf/test/emqx_conf_cli_SUITE.erl @@ -81,7 +81,11 @@ t_load_config(Config) -> Conf#{<<"sources">> => [emqx_authz_schema:default_authz()]}, emqx_conf:get_raw([Authz]) ), - ?assertEqual({error, empty_hocon_file}, emqx_conf_cli:conf(["load", "non-exist-file"])), + ?assertEqual({error, not_found_hocon_file}, emqx_conf_cli:conf(["load", "non-exist-file"])), + EmptyFile = "empty_file.conf", + ok = file:write_file(EmptyFile, <<>>), + ?assertEqual({error, empty_hocon_file}, emqx_conf_cli:conf(["load", EmptyFile])), + ok = file:delete(EmptyFile), ok. t_conflict_mix_conf(Config) ->