fix(plugins): catch stop_app exception

This commit is contained in:
Zaiming (Stone) Shi 2021-12-17 08:30:37 +01:00
parent f15efb4930
commit 58f32c2572
1 changed files with 12 additions and 6 deletions

View File

@ -242,7 +242,7 @@ ensure_stopped(NameVsn) ->
tryit("stop_plugin", tryit("stop_plugin",
fun() -> fun() ->
Plugin = do_read_plugin(NameVsn), Plugin = do_read_plugin(NameVsn),
ok = ensure_apps_stopped(Plugin) ensure_apps_stopped(Plugin)
end). end).
%% @doc Stop and then start the plugin. %% @doc Stop and then start the plugin.
@ -294,16 +294,22 @@ do_ensure_started(NameVsn) ->
%% try the function, catch 'throw' exceptions as normal 'error' return %% try the function, catch 'throw' exceptions as normal 'error' return
%% other exceptions with stacktrace returned. %% other exceptions with stacktrace returned.
tryit(What, F) -> tryit(WhichOp, F) ->
try try
F() F()
catch catch
throw : Reason -> throw : Reason ->
%% thrown exceptions are known errors
%% translate to a return value without stacktrace
{error, Reason}; {error, Reason};
error : Reason : Stacktrace -> error : Reason : Stacktrace ->
Error = "failed_to_" ++ What, %% unexpected errors, log stacktrace
?SLOG(error, #{msg => Error, exception => Reason, stacktrace => Stacktrace}), ?SLOG(warning, #{ msg => "plugin_op_failed"
{error, Error} , which_op => WhichOp
, exception => Reason
, stacktrace => Stacktrace
}),
{error, {failed, WhichOp}}
end. end.
%% read plugin info from the JSON file %% read plugin info from the JSON file
@ -473,7 +479,7 @@ ensure_apps_stopped(#{<<"rel_apps">> := Apps}) ->
{AppName, _AppVsn} = parse_name_vsn(NameVsn), {AppName, _AppVsn} = parse_name_vsn(NameVsn),
AppName AppName
end, Apps), end, Apps),
case stop_apps(AppsToStop) of case tryit("stop_apps", fun() -> stop_apps(AppsToStop) end) of
{ok, []} -> {ok, []} ->
%% all apps stopped %% all apps stopped
ok; ok;