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"
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,
# then also initialize the paths to the plugins.
require "bundler"
Bundler.setup
# Stdout/stderr should not buffer output
$stdout.sync = true
$stderr.sync = true
env = nil
begin
require 'log4r'
require 'vagrant'
require 'vagrant/cli'
@ -71,10 +74,6 @@ require 'vagrant/util/platform'
logger = Log4r::Logger.new("vagrant::bin::vagrant")
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
# environment.
opts = {}
@ -118,8 +117,6 @@ opts[:ui_class] ||= Vagrant::UI::Colored
argv << "--"
argv += argv_extra
env = nil
begin
# Create the environment, which is the cwd of wherever the
# `vagrant` command was invoked from
logger.debug("Creating Vagrant environment")
@ -141,6 +138,8 @@ begin
# Exit with the exit status from our CLI command
exit(exit_status)
rescue Vagrant::Errors::VagrantError => e
require 'log4r'
logger = Log4r::Logger.new("vagrant::bin::vagrant")
logger.error("Vagrant experienced an error! Details:")
logger.error(e.inspect)
logger.error(e.message)

View File

@ -262,4 +262,10 @@ Vagrant.source_root.join("plugins").children(true).each do |directory|
end
# 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)
end
class PluginLoadFailed < VagrantError
error_key(:plugin_load_failed)
end
class PluginLoadFailedWithOutput < VagrantError
error_key(:plugin_load_failed_with_output)
end
class PluginNotFound < VagrantError
error_key(:plugin_not_found)
end

View File

@ -531,19 +531,10 @@ en:
%{conflicts}
plugin_load_error: |-
The plugin "%{plugin}" could not be found. Please make sure that it is
properly installed via `vagrant plugin`. Note that plugins made for
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.
The plugins failed to load properly. The error message given is
shown below.
stdout: %{stdout}
stderr: %{stderr}
%{message}
plugin_not_found: |-
The plugin '%{name}' could not be found. Please install this plugin
prior to attempting to do anything with it.