fix: try Expr of only catches exceptions in Expr but not cases clauses

This commit is contained in:
Zaiming (Stone) Shi 2022-02-10 13:12:22 +01:00
parent 525bf47618
commit 91366a71a4
1 changed files with 12 additions and 6 deletions

View File

@ -90,6 +90,7 @@ get_raw_cluster_override_conf() ->
-spec init(term()) -> {ok, state()}.
init(_) ->
process_flag(trap_exit, true),
{ok, #{handlers => #{?MOD => ?MODULE}}}.
handle_call({add_handler, ConfKeyPath, HandlerName}, _From, State = #{handlers := Handlers}) ->
@ -150,12 +151,8 @@ deep_put_handler2(Key, KeyPath, Handlers, Mod) ->
end.
handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->
try process_update_request(ConfKeyPath, Handlers, UpdateArgs) of
{ok, NewRawConf, OverrideConf, Opts} ->
check_and_save_configs(SchemaModule, ConfKeyPath, Handlers, NewRawConf,
OverrideConf, UpdateArgs, Opts);
{error, Result} ->
{error, Result}
try
do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs)
catch
throw : Reason ->
{error, Reason};
@ -168,6 +165,15 @@ handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->
{error, config_update_crashed}
end.
do_handle_update_request(SchemaModule, ConfKeyPath, Handlers, UpdateArgs) ->
case process_update_request(ConfKeyPath, Handlers, UpdateArgs) of
{ok, NewRawConf, OverrideConf, Opts} ->
check_and_save_configs(SchemaModule, ConfKeyPath, Handlers, NewRawConf,
OverrideConf, UpdateArgs, Opts);
{error, Result} ->
{error, Result}
end.
process_update_request(ConfKeyPath, _Handlers, {remove, Opts}) ->
OldRawConf = emqx_config:get_root_raw(ConfKeyPath),
BinKeyPath = bin_path(ConfKeyPath),