Просмотр исходного кода

fix: remove the corrupted plugin after read relup package failed

Shawn 1 год назад
Родитель
Сommit
46e0961534
1 измененных файлов с 15 добавлено и 4 удалено
  1. 15 4
      apps/emqx_management/src/emqx_mgmt_api_relup.erl

+ 15 - 4
apps/emqx_management/src/emqx_mgmt_api_relup.erl

@@ -431,7 +431,18 @@ validate_name(Name) ->
 '/relup/package'(get, _) ->
 '/relup/package'(get, _) ->
     case get_installed_packages() of
     case get_installed_packages() of
         [PluginInfo] ->
         [PluginInfo] ->
-            {200, format_package_info(PluginInfo)};
+            case get_package_info(PluginInfo) of
+                {error, Reason} ->
+                    ?SLOG(error, #{
+                        msg => get_package_info_failed,
+                        reason => Reason,
+                        details => <<"the corrupted plugin will be deleted">>
+                    }),
+                    delete_installed_packages(),
+                    return_internal_error(Reason);
+                Info when is_map(Info) ->
+                    {200, Info}
+            end;
         [] ->
         [] ->
             return_not_found(<<"No relup package is installed">>)
             return_not_found(<<"No relup package is installed">>)
     end;
     end;
@@ -580,13 +591,13 @@ delete_installed_packages() ->
         get_installed_packages()
         get_installed_packages()
     ).
     ).
 
 
-format_package_info(PluginInfo) when is_map(PluginInfo) ->
+get_package_info(PluginInfo) when is_map(PluginInfo) ->
     Vsn = maps_get(rel_vsn, PluginInfo),
     Vsn = maps_get(rel_vsn, PluginInfo),
     case call_emqx_relup_main(get_package_info, [], no_pkg_installed) of
     case call_emqx_relup_main(get_package_info, [], no_pkg_installed) of
         no_pkg_installed ->
         no_pkg_installed ->
-            throw({get_pkg_info_failed, <<"No relup package is installed">>});
+            {error, <<"No relup package is installed">>};
         {error, Reason} ->
         {error, Reason} ->
-            throw({get_pkg_info_failed, Reason});
+            {error, Reason};
         {ok, #{base_vsns := BaseVsns, change_logs := ChangeLogs}} ->
         {ok, #{base_vsns := BaseVsns, change_logs := ChangeLogs}} ->
             #{
             #{
                 name => name_vsn(?PLUGIN_NAME, Vsn),
                 name => name_vsn(?PLUGIN_NAME, Vsn),