core: Catch plugin load errors and show them to the user ina friendly way
This commit is contained in:
parent
010874ffad
commit
7c995caae5
109
bin/vagrant
109
bin/vagrant
|
@ -54,72 +54,69 @@ 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
|
||||||
|
|
||||||
require 'log4r'
|
|
||||||
require 'vagrant'
|
|
||||||
require 'vagrant/cli'
|
|
||||||
require 'vagrant/util/platform'
|
|
||||||
|
|
||||||
# Create a logger right away
|
|
||||||
logger = Log4r::Logger.new("vagrant::bin::vagrant")
|
|
||||||
logger.info("`vagrant` invoked: #{ARGV.inspect}")
|
|
||||||
|
|
||||||
# Stdout/stderr should not buffer output
|
# Stdout/stderr should not buffer output
|
||||||
$stdout.sync = true
|
$stdout.sync = true
|
||||||
$stderr.sync = true
|
$stderr.sync = true
|
||||||
|
|
||||||
# These will be the options that are passed to initialze the Vagrant
|
|
||||||
# environment.
|
|
||||||
opts = {}
|
|
||||||
|
|
||||||
# Disable color in a few cases:
|
|
||||||
#
|
|
||||||
# * --no-color is anywhere in our arguments
|
|
||||||
# * STDOUT is not a TTY
|
|
||||||
# * The terminal doesn't support colors (Windows)
|
|
||||||
#
|
|
||||||
if argv.include?("--no-color") || ENV["VAGRANT_NO_COLOR"]
|
|
||||||
# Delete the argument from the list so that it doesn't
|
|
||||||
# cause any invalid arguments down the road.
|
|
||||||
argv.delete("--no-color")
|
|
||||||
|
|
||||||
opts[:ui_class] = Vagrant::UI::Basic
|
|
||||||
elsif !Vagrant::Util::Platform.terminal_supports_colors?
|
|
||||||
opts[:ui_class] = Vagrant::UI::Basic
|
|
||||||
elsif !$stdout.tty? && !Vagrant::Util::Platform.cygwin?
|
|
||||||
# Cygwin always reports STDOUT is not a TTY, so we only disable
|
|
||||||
# colors if its not a TTY AND its not Cygwin.
|
|
||||||
opts[:ui_class] = Vagrant::UI::Basic
|
|
||||||
end
|
|
||||||
|
|
||||||
# Also allow users to force colors.
|
|
||||||
if argv.include?("--color")
|
|
||||||
argv.delete("--color")
|
|
||||||
opts[:ui_class] = Vagrant::UI::Colored
|
|
||||||
end
|
|
||||||
|
|
||||||
# Highest precedence is if we have enabled machine-readable output
|
|
||||||
if argv.include?("--machine-readable")
|
|
||||||
argv.delete("--machine-readable")
|
|
||||||
opts[:ui_class] = Vagrant::UI::MachineReadable
|
|
||||||
end
|
|
||||||
|
|
||||||
# Default to colored output
|
|
||||||
opts[:ui_class] ||= Vagrant::UI::Colored
|
|
||||||
|
|
||||||
# Recombine the arguments
|
|
||||||
argv << "--"
|
|
||||||
argv += argv_extra
|
|
||||||
|
|
||||||
env = nil
|
env = nil
|
||||||
begin
|
begin
|
||||||
|
require 'log4r'
|
||||||
|
require 'vagrant'
|
||||||
|
require 'vagrant/cli'
|
||||||
|
require 'vagrant/util/platform'
|
||||||
|
|
||||||
|
# Create a logger right away
|
||||||
|
logger = Log4r::Logger.new("vagrant::bin::vagrant")
|
||||||
|
logger.info("`vagrant` invoked: #{ARGV.inspect}")
|
||||||
|
|
||||||
|
# These will be the options that are passed to initialze the Vagrant
|
||||||
|
# environment.
|
||||||
|
opts = {}
|
||||||
|
|
||||||
|
# Disable color in a few cases:
|
||||||
|
#
|
||||||
|
# * --no-color is anywhere in our arguments
|
||||||
|
# * STDOUT is not a TTY
|
||||||
|
# * The terminal doesn't support colors (Windows)
|
||||||
|
#
|
||||||
|
if argv.include?("--no-color") || ENV["VAGRANT_NO_COLOR"]
|
||||||
|
# Delete the argument from the list so that it doesn't
|
||||||
|
# cause any invalid arguments down the road.
|
||||||
|
argv.delete("--no-color")
|
||||||
|
|
||||||
|
opts[:ui_class] = Vagrant::UI::Basic
|
||||||
|
elsif !Vagrant::Util::Platform.terminal_supports_colors?
|
||||||
|
opts[:ui_class] = Vagrant::UI::Basic
|
||||||
|
elsif !$stdout.tty? && !Vagrant::Util::Platform.cygwin?
|
||||||
|
# Cygwin always reports STDOUT is not a TTY, so we only disable
|
||||||
|
# colors if its not a TTY AND its not Cygwin.
|
||||||
|
opts[:ui_class] = Vagrant::UI::Basic
|
||||||
|
end
|
||||||
|
|
||||||
|
# Also allow users to force colors.
|
||||||
|
if argv.include?("--color")
|
||||||
|
argv.delete("--color")
|
||||||
|
opts[:ui_class] = Vagrant::UI::Colored
|
||||||
|
end
|
||||||
|
|
||||||
|
# Highest precedence is if we have enabled machine-readable output
|
||||||
|
if argv.include?("--machine-readable")
|
||||||
|
argv.delete("--machine-readable")
|
||||||
|
opts[:ui_class] = Vagrant::UI::MachineReadable
|
||||||
|
end
|
||||||
|
|
||||||
|
# Default to colored output
|
||||||
|
opts[:ui_class] ||= Vagrant::UI::Colored
|
||||||
|
|
||||||
|
# Recombine the arguments
|
||||||
|
argv << "--"
|
||||||
|
argv += argv_extra
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue