From 96baf4ccdbd12227c33148b8e0e2b1a2dbb2fd50 Mon Sep 17 00:00:00 2001 From: Zhongwen Deng Date: Mon, 23 May 2022 14:08:14 +0800 Subject: [PATCH] fix: don't add default if root_key not found --- apps/emqx/src/emqx_config.erl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/emqx/src/emqx_config.erl b/apps/emqx/src/emqx_config.erl index f4a5387d4..f0db4a275 100644 --- a/apps/emqx/src/emqx_config.erl +++ b/apps/emqx/src/emqx_config.erl @@ -334,14 +334,18 @@ raw_conf_with_default(SchemaMod, RootNames, RawConf) -> true -> Acc; false -> - {_, {_, Schema}} = lists:keyfind(Name, 1, hocon_schema:roots(SchemaMod)), - Default = - case hocon_schema:field_schema(Schema, type) of - ?ARRAY(_) -> []; - ?LAZY(?ARRAY(_)) -> []; - _ -> #{} - end, - Acc#{Name => Default} + case lists:keyfind(Name, 1, hocon_schema:roots(SchemaMod)) of + false -> + Acc; + {_, {_, Schema}} -> + Default = + case hocon_schema:field_schema(Schema, type) of + ?ARRAY(_) -> []; + ?LAZY(?ARRAY(_)) -> []; + _ -> #{} + end, + Acc#{Name => Default} + end end end, RawDefault = lists:foldl(Fun, #{}, RootNames),