From 3df6088db0278a8df60f00cd0a7ba7ea6be848dd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 3 Feb 2013 14:13:27 -0800 Subject: [PATCH] Make plugin loading more robust to errors --- lib/vagrant.rb | 11 +++++++++++ lib/vagrant/environment.rb | 6 +++++- lib/vagrant/errors.rb | 4 ++++ templates/locales/en.yml | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 412bcc320..4d6840633 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -172,6 +172,17 @@ module Vagrant require name rescue LoadError raise Errors::PluginLoadError, :plugin => name + rescue Exception => e + # Since this is a rare case, we create a one-time logger here + # in order to output the error + logger = Log4r::Logger.new("vagrant::root") + logger.error("Failed to load plugin: #{name}") + logger.error(" -- Error: #{e.inspect}") + logger.error(" -- Backtrace:") + logger.error(e.backtrace.join("\n")) + + # And raise an error itself + raise Errors::PluginLoadFailed, :plugin => name end end end diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index fafa7d224..af779b769 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -610,7 +610,11 @@ module Vagrant data = JSON.parse(plugins_json_file.read) data["installed"].each do |plugin| @logger.info("Loading plugin from JSON: #{plugin}") - Vagrant.require_plugin(plugin) + begin + Vagrant.require_plugin(plugin) + rescue Errors::PluginLoadFailed => e + @ui.error(e.message) + end end end end diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index d3823ba5e..1eeaf686f 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -349,6 +349,10 @@ module Vagrant error_key(:plugin_load_error) end + class PluginLoadFailed < VagrantError + error_key(:plugin_load_failed) + end + class SCPPermissionDenied < VagrantError status_code(82) error_key(:scp_permission_denied) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index f00f7e0d9..e50f67159 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -178,6 +178,8 @@ en: plugin_load_error: |- The plugin "%{plugin}" could not be found. Please make sure that it is properly installed via `vagrant plugin`. + plugin_load_failed: |- + Failed to load the "%{plugin}" plugin. View logs for more details. port_collision_resume: |- This VM cannot be resumed, because the forwarded ports would collide with another running virtual machine. Normally, Vagrant will attempt to fix this