Kaynağa Gözat

fix: don't add default if root_key not found

Zhongwen Deng 3 yıl önce
ebeveyn
işleme
96baf4ccdb
1 değiştirilmiş dosya ile 12 ekleme ve 8 silme
  1. 12 8
      apps/emqx/src/emqx_config.erl

+ 12 - 8
apps/emqx/src/emqx_config.erl

@@ -334,14 +334,18 @@ raw_conf_with_default(SchemaMod, RootNames, RawConf) ->
             true ->
             true ->
                 Acc;
                 Acc;
             false ->
             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
     end,
     end,
     RawDefault = lists:foldl(Fun, #{}, RootNames),
     RawDefault = lists:foldl(Fun, #{}, RootNames),