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

View File

@ -119,6 +119,10 @@ module Vagrant
end end
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] [root, warnings, errors]
end end

View File

@ -397,6 +397,10 @@ en:
run_list_empty: "Run list must not be empty." run_list_empty: "Run list must not be empty."
server_url_empty: "Chef server URL must be populated." 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." 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: root:
bad_key: |- bad_key: |-
Unknown configuration section '%{key}'. Unknown configuration section '%{key}'.