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

This commit is contained in:
Shawn 2021-08-12 14:38:10 +08:00
parent 8dbb14b668
commit b652a64dbb
3 changed files with 6 additions and 8 deletions

View File

@ -214,15 +214,13 @@ get_default_value([RootName | _] = KeyPath) ->
BinKeyPath = [bin(Key) || Key <- KeyPath],
case find_raw([RootName]) of
{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
{not_found, _, _} -> {error, no_default_value};
{ok, Val} -> {ok, Val}
end
catch error:_ ->
{error, required_conf}
catch error : Reason -> {error, Reason}
end;
{not_found, _, _} ->
{error, {rootname_not_found, RootName}}

View File

@ -82,8 +82,8 @@ handle_call({add_child, ConfKeyPath, HandlerName}, _From,
handle_call({change_config, SchemaModule, ConfKeyPath, UpdateArgs}, _From,
#{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
{NewRawConf, OverrideConf} = process_upadate_request(ConfKeyPath, OldRawConf,
Handlers, UpdateArgs),

View File

@ -46,7 +46,7 @@
-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() ->
{config_apis() ++ [config_reset_api()], []}.