39 Commits

Author SHA1 Message Date
hashicorp-copywrite[bot]
36a312ee26
add missing license headers and update copyright file headers to BUS-1.1 2023-08-10 21:53:25 +01:00
Chris Roberts
4d403ef02a Only raise error if version load is nil 2022-06-15 11:15:08 -07:00
Chris Roberts
2274efa568 Add helper method for performing partial loads 2022-06-15 11:06:33 -07:00
Chris Roberts
6d0e08942b
Convert error logger message to warn 2022-04-25 12:26:39 -05:00
Brian Cain
ace67ccdeb
Remove platform require since it is no longer required in file 2019-09-10 13:28:37 -07:00
Brian Cain
a22acba467
Simplify line and path checks for exception handling in config loading 2019-09-10 13:27:23 -07:00
Brian Cain
ccf99d8c0c
Fixes #11022: Show proper path & letter drive on exceptions for windows
Prior to this commit, vagrant was not grabbing all of the tokens on
Windows for showing the full drive because the ruby api for it behaves
differenly on windows compared to other platforms. This commit changes
that by ensuring the letter drive is attached to the path when showing
an exception.
2019-09-06 13:37:38 -07:00
Brian Cain
627babe15e (#9055) Print more helpful error message for NameEror exceptions
This commit adds some additional handling for when Vagrant loads config
files. Instead of showing the basic ruby exception, it prints a more
helpful error message and tries to direct the user to the line number
and file where the exception is occuring.
2017-12-14 15:31:48 -08:00
Brian Cain
774e19b152 Disable loading identical Vagrantfile twice from same dir
Prior to this commit, if a user set the env var VAGRANT_HOME to be the
same directory where the project home is, Vagrant would load that file
twice and merge its config. This caused various provisioner and other
provider blocks to unexpectedly run twice. This commit updates the
config loader to look and see if the `:root` and `:home` procs are
equal, and if so, removes the `:home` object so that it isn't loaded and
duplicated. This commit however does not prevent duplicate loading if an
identical Vagrantfile exists in the home and project dir if those
locations are different.
2017-06-22 09:04:21 -07:00
Mitchell Hashimoto
c471f37955 core: parse line numbers for Vagrantfile syntax errors on Win [GH-6445] 2015-11-20 15:34:52 -08:00
Sam Phippen
eeb750cd33 Catch encoding problems with sources provided to Vagrant::Config::Loader#set
Here we implement a naive solution to #5605 which catches the case that
a provided source contains an object which cannot be inspected, because
an object contained within in has an #inspect string that returns a
string that is incompatible with the encoding in
`Encoding.default_external` or a string which cannot be downcast to
7-bit ascii.

The Ruby VM implementation of "#inspect" implements this checking on
these lines of code: http://git.io/vZYNS. A Ruby level override of
this method does not cause this problem. For example:

```ruby
class Foo
  def inspect
    "😍".encode("UTF-16LE")
  end
```

will not cause the problem, because that's a Ruby implementation and the
VM's checks don't occur.

However, if we have an Object which **does** use the VM implementation
of inspect, that contains an object that has an inspect string which
returns non-ascii, we encounter the bug. For example:

```ruby
class Bar
  def inspect
    "😍".encode("UTF-16LE")
  end
end

class Foo
  def initialize
     @bar = Bar.new
  end
end

Foo.new.inspect
```

Will cause the issue.

The solution this patch provides basically catches the encoding error
and inserts a string which attempts to help the user work out which
object was provided without blowing up. Most likely, this was caused
by a user having a weird encoding coming out of one of the sources
passed in, but without a full repro case, it's not clear whether a patch
should be applied to a different object in the system.

Closes #5605.
2015-09-08 17:30:50 +01:00
Seth Vargo
6b2ef13785 Be more defensive when trying to get the line number
Since this is the last line of defense before raising an error, we want to make
sure we don't cause an error while trying to render the error.
2015-05-31 18:32:23 -07:00
Adam Spiers
ce13051d61 eliminate guesswork with Vagrantfile errors
If the Vagrantfile has some kind of error, display not only
its path and the exception message, but also the originating
line number and exception class.

Also log the full backtrace when the error is in a provider
block, just as it is done when it's outside a provider block.
2015-05-31 18:25:51 -07:00
Seth Vargo
d2874064f4 Use .key? instead of .has_key? 2015-01-05 18:29:01 -05:00
Kalman Hazins
bb052366f7 Change symbols inside hashes to 1.9 JSON-like syntax 2014-05-22 12:35:12 -04:00
Mitchell Hashimoto
92df8cf6ae Handle a lot of TODOs 2014-04-29 16:50:58 -07:00
Mitchell Hashimoto
87026b2d9e Remove old TOOD that was fulfilled 2013-02-05 22:17:00 -08:00
Mitchell Hashimoto
a8c7ad30ee Be a bit more fine grained about errors that are reported for Vfiles 2013-01-31 18:52:29 -08:00
Mitchell Hashimoto
e9327c4a28 Better logging in the config logger 2013-01-30 20:12:41 -08:00
Mitchell Hashimoto
c57ba9de58 Give a nice human-friendly error message when problems loading Vfile 2013-01-30 20:01:41 -08:00
Mitchell Hashimoto
2d57afbbda Support warnings/errors when upgrading Vagrantfiles internally 2013-01-20 22:04:50 -05:00
Mitchell Hashimoto
2da812bd48 Change log levels of some messages that are useful 2012-12-23 16:29:24 -08:00
Mitchell Hashimoto
0180ed849d Move config loader order out from an ivar into a param for the #load
method
2012-12-23 16:29:23 -08:00
Mitchell Hashimoto
6231bef3f0 Simple logging text change 2012-06-23 23:40:55 -07:00
Mitchell Hashimoto
7a299ae2de Configuration loader can handle upgrading.
The basic process for this is to:

1. Load the configuration using the proper loader for that version. i.e.
   if you're loading V1 config, then use the V1 loader.
2. If we just loaded a version that isn't current (imagine we're
   currently at V3), then we need to upgrade that config. So we first
   ask the V2 loader to upgrade the V1 config to V2, then we ask the V3
   loader to upgrade the V2 config to V3. We keep track of warnings and
   errors throughout this process.
3. Finally, we have a current config, so we merge it into the in-process
   configuration that is being loaded.
2012-06-23 19:56:31 -07:00
Mitchell Hashimoto
70fb804128 Configuration versions can finalize config after loading
This is useful so that it can take a look at the final loaded
configuration object and possibly make some tweaks to the configuration
object. The use case this was built for was so that config V1 can verify
that there is always at least a single VM defined as a sub-VM, the
"default" VM.
2012-06-23 12:27:32 -07:00
Mitchell Hashimoto
7e19d6849b Config loader no longer assumes latest version for procs.
Previously, all procs were assumed to just be the current version. This
is certainly not going to be true always so now the version number of
the configuration must be explicit if you're assigning a proc to the
configuration loader.
2012-06-23 12:06:54 -07:00
Mitchell Hashimoto
b3db82e516 Separate out the versions the config loader knows as init params.
This means that the Config::Loader now only knows how to load
configuration for versions used to initialize the class. This lets
things like the tests be completely isolated from what the actual
configuration is for Vagrant. This will be immensely useful to verify
that the loader functionality works for non-trivial bits (like
upgrading) without depending on Vagrant's upgrading functionality.
2012-06-23 11:33:53 -07:00
Mitchell Hashimoto
3204b3a580 Vagrant.configure and versioned configuration
Vagrant.configure is now how configuration is done in Vagrantfiles
(previously it was Vagrant::Config.run). This function takes a single
argument which is the version of configuration to use.

Various internals were updated for this new versioned configuration.

Note that multiple versions of configuration aren't yet used so aren't
fully supported by Vagrant, but the foundation is being set here.
2012-05-21 21:47:01 -07:00
Mitchell Hashimoto
95e554314e Foundation for supporting multiple version types
I created VersionBase which is the abstract base class for any
configuration versions. Configuration versions are responsible for
knowing how to load configuration given a proc (from a
Vagrant.configure block), as well as merging configuration procs. In the
future, it will have to upgrade versions as well. This is not done yet.

The VERSIONS constant was added to Vagrant::Config which is a registry
to keep track of all the available configuration versions. The
VERSIONS_ORDER constant is an array of the ordering of these versions.
The ordering is important so that in the future Vagrant can attempt to
gracefully upgrade the configurations. It is also used to determine the
current configuration version (which is assumed to be the last version
in the order).

The loader was modified to use the current version and the VERSIONS
registry instead of hardcoding V1.
2012-05-20 17:47:24 -07:00
Mitchell Hashimoto
b38fb5e974 Loader uses the new configuration classes 2012-04-18 17:03:34 -07:00
Mitchell Hashimoto
c2fbbe7dee Better logging for config loading 2012-02-15 18:23:05 -08:00
Mitchell Hashimoto
008132b3cb Run each config proc only once 2012-01-11 20:59:21 -08:00
Mitchell Hashimoto
7c9c6e34ce Change caching behavior of config procs for the config loader 2012-01-11 16:58:40 -08:00
Mitchell Hashimoto
99982fb26e VM-specific configuration now works. 2011-12-03 19:05:50 -08:00
Mitchell Hashimoto
73a672cff1 load_config! is kind of working again.
Specifically: Global configuration load appears to be working. More
unit tests should reveal if proper VM configuration is loading.
2011-12-03 18:31:17 -08:00
Mitchell Hashimoto
02cc1447dc Configuration files are only loaded once 2011-12-03 17:42:16 -08:00
Mitchell Hashimoto
15c56a1f4c Configuration loads. Lots of refactor to do still. 2011-12-03 17:29:28 -08:00
Mitchell Hashimoto
1a8c4199b2 Introduce Config::Loader
Config::Loader will be the new class responsible for loading configuration
and replaces the previous dual-role "Vagrant::Config" played. While this
commit is very early-stage, once this new architecture is flushed out, it
will make loading, using, and extending configuration much easier and cleaner.

Additionally, I believe this will help post Vagrant 1.0 if multi-language
configuration is implemented.
2011-12-03 17:12:48 -08:00