Capture missing key calls in V1 configs and record them as warnings

This commit is contained in:
Mitchell Hashimoto 2013-02-28 00:06:49 -08:00
parent 18492d5d70
commit d15acde8c0
3 changed files with 20 additions and 6 deletions

View File

@ -1,3 +1,6 @@
require "ostruct"
require "set"
module Vagrant
module Config
module V1
@ -9,8 +12,9 @@ module Vagrant
#
# @param [Hash] config_map Map of key to config class.
def initialize(config_map, keys=nil)
@keys = keys || {}
@config_map = config_map
@keys = keys || {}
@config_map = config_map
@missing_key_calls = Set.new
end
# We use method_missing as a way to get the configuration that is
@ -25,8 +29,9 @@ module Vagrant
@keys[name] = config_klass.new
return @keys[name]
else
# Super it up to probably raise a NoMethodError
super
# Record access to a missing key as an error
@missing_key_calls.add(name.to_s)
return OpenStruct.new
end
end
@ -45,8 +50,9 @@ module Vagrant
# clashes with potential configuration keys.
def __internal_state
{
"config_map" => @config_map,
"keys" => @keys
"config_map" => @config_map,
"keys" => @keys,
"missing_key_calls" => @missing_key_calls
}
end
end

View File

@ -119,6 +119,10 @@ module Vagrant
end
end
old.__internal_state["missing_key_calls"].to_a.sort.each do |key|
warnings << I18n.t("vagrant.config.loader.bad_v1_key", :key => key)
end
[root, warnings, errors]
end

View File

@ -397,6 +397,10 @@ en:
run_list_empty: "Run list must not be empty."
server_url_empty: "Chef server URL must be populated."
validation_key_path: "Validation key path must be valid path to your chef server validation key."
loader:
bad_v1_key: |-
Unknown configuration section '%{key}'. If this section was part of
a Vagrant 1.0.x plugin, note that 1.0.x plugins are incompatible with 1.1+.
root:
bad_key: |-
Unknown configuration section '%{key}'.