Преглед на файлове

fix: log error when failed to install plugin

the error return is a map with details.
prior to this change only the reason is returned in the api response,
now the error map is logged at error level to help troubleshooting
Zaiming (Stone) Shi преди 2 години
родител
ревизия
5427ebc5f1
променени са 2 файла, в които са добавени 4 реда и са изтрити 3 реда
  1. 3 2
      apps/emqx_management/src/emqx_mgmt_api_plugins.erl
  2. 1 1
      apps/emqx_plugins/src/emqx_plugins.erl

+ 3 - 2
apps/emqx_management/src/emqx_mgmt_api_plugins.erl

@@ -399,7 +399,7 @@ do_install_package(FileName, Bin) ->
                 end,
                 end,
             {400, #{
             {400, #{
                 code => 'BAD_PLUGIN_INFO',
                 code => 'BAD_PLUGIN_INFO',
-                message => iolist_to_binary([Reason, ":", FileName])
+                message => iolist_to_binary([Reason, ": ", FileName])
             }}
             }}
     end.
     end.
 
 
@@ -445,7 +445,8 @@ install_package(FileName, Bin) ->
     case emqx_plugins:ensure_installed(PackageName) of
     case emqx_plugins:ensure_installed(PackageName) of
         {error, #{return := not_found}} = NotFound ->
         {error, #{return := not_found}} = NotFound ->
             NotFound;
             NotFound;
-        {error, _Reason} = Error ->
+        {error, Reason} = Error ->
+            ?SLOG(error, Reason#{msg => "failed_to_install_plugin"}),
             _ = file:delete(File),
             _ = file:delete(File),
             Error;
             Error;
         Result ->
         Result ->

+ 1 - 1
apps/emqx_plugins/src/emqx_plugins.erl

@@ -83,7 +83,7 @@
 describe(NameVsn) -> read_plugin(NameVsn, #{fill_readme => true}).
 describe(NameVsn) -> read_plugin(NameVsn, #{fill_readme => true}).
 
 
 %% @doc Install a .tar.gz package placed in install_dir.
 %% @doc Install a .tar.gz package placed in install_dir.
--spec ensure_installed(name_vsn()) -> ok | {error, any()}.
+-spec ensure_installed(name_vsn()) -> ok | {error, map()}.
 ensure_installed(NameVsn) ->
 ensure_installed(NameVsn) ->
     case read_plugin(NameVsn, #{}) of
     case read_plugin(NameVsn, #{}) of
         {ok, _} ->
         {ok, _} ->