Make plugin loading more robust to errors

This commit is contained in:
Mitchell Hashimoto 2013-02-03 14:13:27 -08:00
parent 1162c2dbfc
commit 3df6088db0
4 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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