From d15acde8c050c969f97b71ed355419734ce69820 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 28 Feb 2013 00:06:49 -0800 Subject: [PATCH] Capture missing key calls in V1 configs and record them as warnings --- lib/vagrant/config/v1/root.rb | 18 ++++++++++++------ lib/vagrant/config/v2/loader.rb | 4 ++++ templates/locales/en.yml | 4 ++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/vagrant/config/v1/root.rb b/lib/vagrant/config/v1/root.rb index f501a1fb3..ba3288095 100644 --- a/lib/vagrant/config/v1/root.rb +++ b/lib/vagrant/config/v1/root.rb @@ -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 diff --git a/lib/vagrant/config/v2/loader.rb b/lib/vagrant/config/v2/loader.rb index d7f0a8e3d..b0c833982 100644 --- a/lib/vagrant/config/v2/loader.rb +++ b/lib/vagrant/config/v2/loader.rb @@ -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 diff --git a/templates/locales/en.yml b/templates/locales/en.yml index fca27b585..c5e77679b 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -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}'.