core: catch EINVAL on setting env vars [GH-6017]

This commit is contained in:
Mitchell Hashimoto 2015-11-23 09:39:51 -08:00
parent 4e1ba3a027
commit 1405395d81
5 changed files with 36 additions and 6 deletions

View File

@ -72,6 +72,7 @@ BUG FIXES:
retry from scratch [GH-4479] retry from scratch [GH-4479]
- core: line numbers show properly in Vagrantfile syntax errors - core: line numbers show properly in Vagrantfile syntax errors
on Windows [GH-6445] 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: add command with `~` paths on Windows works [GH-5747]
- commands/box: the update command supports CA settings [GH-4473] - commands/box: the update command supports CA settings [GH-4473]
- commands/box: removing all versions and providers of a box will properly - commands/box: removing all versions and providers of a box will properly

View File

@ -7,6 +7,7 @@ require "bundler"
require_relative "shared_helpers" require_relative "shared_helpers"
require_relative "version" require_relative "version"
require_relative "util/safe_env"
module Vagrant module Vagrant
# This class manages Vagrant's interaction with Bundler. Vagrant uses # This class manages Vagrant's interaction with Bundler. Vagrant uses
@ -71,12 +72,15 @@ module Vagrant
# we add all our plugin dependencies. # we add all our plugin dependencies.
@gemfile = build_gemfile(plugins) @gemfile = build_gemfile(plugins)
SafeEnv.change_env do |env|
# Set the environmental variables for Bundler # Set the environmental variables for Bundler
ENV["BUNDLE_APP_CONFIG"] = @appconfigpath env["BUNDLE_APP_CONFIG"] = @appconfigpath
ENV["BUNDLE_CONFIG"] = @configfile.path env["BUNDLE_CONFIG"] = @configfile.path
ENV["BUNDLE_GEMFILE"] = @gemfile.path env["BUNDLE_GEMFILE"] = @gemfile.path
ENV["GEM_PATH"] = env["GEM_PATH"] =
"#{bundle_path}#{::File::PATH_SEPARATOR}#{@gem_path}" "#{bundle_path}#{::File::PATH_SEPARATOR}#{@gem_path}"
end
Gem.clear_paths Gem.clear_paths
end end

View File

@ -344,6 +344,10 @@ module Vagrant
error_key(:downloader_interrupted) error_key(:downloader_interrupted)
end end
class EnvInval < VagrantError
error_key(:env_inval)
end
class EnvironmentNonExistentCWD < VagrantError class EnvironmentNonExistentCWD < VagrantError
error_key(:environment_non_existent_cwd) error_key(:environment_non_existent_cwd)
end end

View File

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

View File

@ -730,6 +730,13 @@ en:
downloader_interrupted: |- downloader_interrupted: |-
The download was interrupted by an external signal. It did not The download was interrupted by an external signal. It did not
complete. 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: |- environment_locked: |-
Vagrant attempted to acquire a lock named '%{name}', but this Vagrant attempted to acquire a lock named '%{name}', but this
lock is being held by another instance of Vagrant already. Please lock is being held by another instance of Vagrant already. Please