From bca1e2ea0903c8ce1c130a08a16f86eff5fb0e44 Mon Sep 17 00:00:00 2001 From: Jean-Sebastien Pedron Date: Wed, 3 Dec 2014 15:43:57 +0100 Subject: Throw an error if at least one plugin's module can't be loaded This prevents a plugin from being enabled if it won't be able to actually run later. A use case for this is a plugin built with Erlang version N, but executed on Erlang version M, where M isn't capable of running the bytecode from N. This was the case with Eralng R14B vs. R15B. The "rabbitmq-plugins enable " command reports the error and the plugin remains disabled. A node reports the error too and refuses to start, exactly as if the plugin was missing. --- src/rabbit_plugins.erl | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl index dfde5289..55f7359b 100644 --- a/src/rabbit_plugins.erl +++ b/src/rabbit_plugins.erl @@ -208,7 +208,27 @@ clean_plugin(Plugin, ExpandDir) -> delete_recursively(rabbit_misc:format("~s/~s", [ExpandDir, Plugin])). prepare_dir_plugin(PluginAppDescPath) -> - code:add_patha(filename:dirname(PluginAppDescPath)). + PluginEbinDir = filename:dirname(PluginAppDescPath), + Plugin = filename:basename(PluginAppDescPath, ".app"), + code:add_patha(PluginEbinDir), + case filelib:wildcard(PluginEbinDir++ "/*.beam") of + [] -> + ok; + [BeamPath | _] -> + Module = list_to_atom(filename:basename(BeamPath, ".beam")), + case code:ensure_loaded(Module) of + {module, _} -> + ok; + {error, badfile} -> + rabbit_log:error("Failed to enable plugin \"~s\": " + "it may have been built with an " + "incompatible (more recent?) " + "version of Erlang~n", [Plugin]), + throw({plugin_built_with_incompatible_erlang, Plugin}); + Error -> + throw({plugin_module_unloadable, Plugin, Error}) + end + end. %%---------------------------------------------------------------------------- -- cgit v1.2.1