瀏覽代碼

fix(config): reset config failed due to rootname not found

Shawn 4 年之前
父節點
當前提交
b652a64dbb

+ 3 - 5
apps/emqx/src/emqx_config.erl

@@ -214,15 +214,13 @@ get_default_value([RootName | _] = KeyPath) ->
     BinKeyPath = [bin(Key) || Key <- KeyPath],
     BinKeyPath = [bin(Key) || Key <- KeyPath],
     case find_raw([RootName]) of
     case find_raw([RootName]) of
         {ok, RawConf} ->
         {ok, RawConf} ->
-            RawConf1 = emqx_map_lib:deep_remove(BinKeyPath, RawConf),
-            SchemaMod = get_schema_mod(RootName),
-            try fill_defaults(SchemaMod, RawConf1) of FullConf ->
+            RawConf1 = emqx_map_lib:deep_remove(BinKeyPath, #{bin(RootName) => RawConf}),
+            try fill_defaults(get_schema_mod(RootName), RawConf1) of FullConf ->
                 case emqx_map_lib:deep_find(BinKeyPath, FullConf) of
                 case emqx_map_lib:deep_find(BinKeyPath, FullConf) of
                     {not_found, _, _} -> {error, no_default_value};
                     {not_found, _, _} -> {error, no_default_value};
                     {ok, Val} -> {ok, Val}
                     {ok, Val} -> {ok, Val}
                 end
                 end
-            catch error:_ ->
-                {error, required_conf}
+            catch error : Reason -> {error, Reason}
             end;
             end;
         {not_found, _, _} ->
         {not_found, _, _} ->
             {error, {rootname_not_found, RootName}}
             {error, {rootname_not_found, RootName}}

+ 2 - 2
apps/emqx/src/emqx_config_handler.erl

@@ -82,8 +82,8 @@ handle_call({add_child, ConfKeyPath, HandlerName}, _From,
 
 
 handle_call({change_config, SchemaModule, ConfKeyPath, UpdateArgs}, _From,
 handle_call({change_config, SchemaModule, ConfKeyPath, UpdateArgs}, _From,
             #{handlers := Handlers} = State) ->
             #{handlers := Handlers} = State) ->
-    OldConf = emqx_config:get_root(ConfKeyPath),
-    OldRawConf = emqx_config:get_root_raw(ConfKeyPath),
+    OldConf = emqx_config:get([]),
+    OldRawConf = emqx_config:get_raw([]),
     Result = try
     Result = try
         {NewRawConf, OverrideConf} = process_upadate_request(ConfKeyPath, OldRawConf,
         {NewRawConf, OverrideConf} = process_upadate_request(ConfKeyPath, OldRawConf,
             Handlers, UpdateArgs),
             Handlers, UpdateArgs),

+ 1 - 1
apps/emqx_management/src/emqx_mgmt_api_configs.erl

@@ -46,7 +46,7 @@
 
 
 -define(MAX_DEPTH, 1).
 -define(MAX_DEPTH, 1).
 
 
--define(ERR_MSG(MSG), io_lib:format("~p", [MSG])).
+-define(ERR_MSG(MSG), list_to_binary(io_lib:format("~p", [MSG]))).
 
 
 api_spec() ->
 api_spec() ->
     {config_apis() ++ [config_reset_api()], []}.
     {config_apis() ++ [config_reset_api()], []}.