core: Catch plugin load errors and show them to the user ina friendly way

This commit is contained in:
Mitchell Hashimoto 2014-01-08 14:45:43 -08:00
parent 010874ffad
commit 7c995caae5
4 changed files with 64 additions and 76 deletions

View File

@ -54,14 +54,17 @@ if argv.include?("--debug")
ENV["VAGRANT_LOG"] = "debug" ENV["VAGRANT_LOG"] = "debug"
end end
# Require some stuff that is NOT dependent on RubyGems
require "vagrant/shared_helpers"
# Setup our dependencies by initializing Bundler. If we're using plugins, # Setup our dependencies by initializing Bundler. If we're using plugins,
# then also initialize the paths to the plugins. # then also initialize the paths to the plugins.
require "bundler" require "bundler"
Bundler.setup Bundler.setup
# Stdout/stderr should not buffer output
$stdout.sync = true
$stderr.sync = true
env = nil
begin
require 'log4r' require 'log4r'
require 'vagrant' require 'vagrant'
require 'vagrant/cli' require 'vagrant/cli'
@ -71,10 +74,6 @@ require 'vagrant/util/platform'
logger = Log4r::Logger.new("vagrant::bin::vagrant") logger = Log4r::Logger.new("vagrant::bin::vagrant")
logger.info("`vagrant` invoked: #{ARGV.inspect}") logger.info("`vagrant` invoked: #{ARGV.inspect}")
# Stdout/stderr should not buffer output
$stdout.sync = true
$stderr.sync = true
# These will be the options that are passed to initialze the Vagrant # These will be the options that are passed to initialze the Vagrant
# environment. # environment.
opts = {} opts = {}
@ -118,8 +117,6 @@ opts[:ui_class] ||= Vagrant::UI::Colored
argv << "--" argv << "--"
argv += argv_extra argv += argv_extra
env = nil
begin
# Create the environment, which is the cwd of wherever the # Create the environment, which is the cwd of wherever the
# `vagrant` command was invoked from # `vagrant` command was invoked from
logger.debug("Creating Vagrant environment") logger.debug("Creating Vagrant environment")
@ -141,6 +138,8 @@ begin
# Exit with the exit status from our CLI command # Exit with the exit status from our CLI command
exit(exit_status) exit(exit_status)
rescue Vagrant::Errors::VagrantError => e rescue Vagrant::Errors::VagrantError => e
require 'log4r'
logger = Log4r::Logger.new("vagrant::bin::vagrant")
logger.error("Vagrant experienced an error! Details:") logger.error("Vagrant experienced an error! Details:")
logger.error(e.inspect) logger.error(e.inspect)
logger.error(e.message) logger.error(e.message)

View File

@ -262,4 +262,10 @@ Vagrant.source_root.join("plugins").children(true).each do |directory|
end end
# If we have plugins enabled, then load those # If we have plugins enabled, then load those
Bundler.require(:plugins) if Vagrant.plugins_enabled? if Vagrant.plugins_enabled?
begin
Bundler.require(:plugins)
rescue Exception => e
raise Vagrant::Errors::PluginLoadError, message: e.to_s
end
end

View File

@ -481,14 +481,6 @@ module Vagrant
error_key(:plugin_load_error) error_key(:plugin_load_error)
end end
class PluginLoadFailed < VagrantError
error_key(:plugin_load_failed)
end
class PluginLoadFailedWithOutput < VagrantError
error_key(:plugin_load_failed_with_output)
end
class PluginNotFound < VagrantError class PluginNotFound < VagrantError
error_key(:plugin_not_found) error_key(:plugin_not_found)
end end

View File

@ -531,19 +531,10 @@ en:
%{conflicts} %{conflicts}
plugin_load_error: |- plugin_load_error: |-
The plugin "%{plugin}" could not be found. Please make sure that it is The plugins failed to load properly. The error message given is
properly installed via `vagrant plugin`. Note that plugins made for shown below.
Vagrant 1.0.x are not compatible with 1.1+ and this error will likely
continue to show when you use `plugin install` with a 1.0.x plugin.
plugin_load_failed: |-
Failed to load the "%{plugin}" plugin. View logs for more details.
plugin_load_failed_with_output: |-
Failed to load the "%{plugin}" plugin. The output from loading
the plugin is shown below. View the logs for complete details.
stdout: %{stdout} %{message}
stderr: %{stderr}
plugin_not_found: |- plugin_not_found: |-
The plugin '%{name}' could not be found. Please install this plugin The plugin '%{name}' could not be found. Please install this plugin
prior to attempting to do anything with it. prior to attempting to do anything with it.