diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c8f48da..e1d260dd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ BUG FIXES: retry from scratch [GH-4479] - core: line numbers show properly in Vagrantfile syntax errors on Windows [GH-6445] + - core: catch errors setting env vars on Windows [GH-6017] - commands/box: add command with `~` paths on Windows works [GH-5747] - commands/box: the update command supports CA settings [GH-4473] - commands/box: removing all versions and providers of a box will properly diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index e6b5aca14..7382cbc59 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -7,6 +7,7 @@ require "bundler" require_relative "shared_helpers" require_relative "version" +require_relative "util/safe_env" module Vagrant # This class manages Vagrant's interaction with Bundler. Vagrant uses @@ -71,12 +72,15 @@ module Vagrant # we add all our plugin dependencies. @gemfile = build_gemfile(plugins) - # Set the environmental variables for Bundler - ENV["BUNDLE_APP_CONFIG"] = @appconfigpath - ENV["BUNDLE_CONFIG"] = @configfile.path - ENV["BUNDLE_GEMFILE"] = @gemfile.path - ENV["GEM_PATH"] = - "#{bundle_path}#{::File::PATH_SEPARATOR}#{@gem_path}" + SafeEnv.change_env do |env| + # Set the environmental variables for Bundler + env["BUNDLE_APP_CONFIG"] = @appconfigpath + env["BUNDLE_CONFIG"] = @configfile.path + env["BUNDLE_GEMFILE"] = @gemfile.path + env["GEM_PATH"] = + "#{bundle_path}#{::File::PATH_SEPARATOR}#{@gem_path}" + end + Gem.clear_paths end diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 341688308..d4009f347 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -344,6 +344,10 @@ module Vagrant error_key(:downloader_interrupted) end + class EnvInval < VagrantError + error_key(:env_inval) + end + class EnvironmentNonExistentCWD < VagrantError error_key(:environment_non_existent_cwd) end diff --git a/lib/vagrant/util/safe_env.rb b/lib/vagrant/util/safe_env.rb new file mode 100644 index 000000000..8d7d8baf1 --- /dev/null +++ b/lib/vagrant/util/safe_env.rb @@ -0,0 +1,14 @@ +module Vagrant + module Util + class SafeEnv + # This yields an environment hash to change and catches any issues + # while changing the environment variables and raises a helpful error + # to end users. + def self.change_env + yield ENV + rescue Errno::EINVAL + raise Errors::EnvInval + end + end + end +end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index f4bde55d3..60c7e3838 100755 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -730,6 +730,13 @@ en: downloader_interrupted: |- The download was interrupted by an external signal. It did not complete. + env_inval: |- + Vagrant received an "EINVAL" error while attempting to set some + environment variables. This is usually caused by the total size of your + environment variables being too large. Vagrant sets a handful of + environment variables to function and requires this to work. Please + delete some environment variables prior to executing Vagrant to + fix this. environment_locked: |- Vagrant attempted to acquire a lock named '%{name}', but this lock is being held by another instance of Vagrant already. Please