From 361cc1ae40b675b1a4f5817b9a08b8767a56acea Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 28 Mar 2013 15:38:32 -0700 Subject: [PATCH] Proper error message if invalid provisioner is used [GH-1515] --- CHANGELOG.md | 2 ++ plugins/kernel_v2/config/vm.rb | 6 ++++++ plugins/kernel_v2/config/vm_provisioner.rb | 14 ++++++++++++-- templates/locales/en.yml | 6 ++---- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d06d6e7ec..e46d73fe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 1.1.5 (unreleased) +BUG FIXES: + - Proper error message if invalid provisioner is used. [GH-1515] ## 1.1.4 (March 25, 2013) diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index f069a3f19..389a655a2 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -312,6 +312,12 @@ module VagrantPlugins # Validate provisioners @provisioners.each do |vm_provisioner| + if vm_provisioner.invalid? + errors["vm"] << I18n.t("vagrant.config.vm.provisioner_not_found", + :name => vm_provisioner.name) + next + end + if vm_provisioner.config provisioner_errors = vm_provisioner.config.validate(machine) if provisioner_errors diff --git a/plugins/kernel_v2/config/vm_provisioner.rb b/plugins/kernel_v2/config/vm_provisioner.rb index ede80bc43..66ea5c7e1 100644 --- a/plugins/kernel_v2/config/vm_provisioner.rb +++ b/plugins/kernel_v2/config/vm_provisioner.rb @@ -19,13 +19,15 @@ module VagrantPlugins @logger = Log4r::Logger.new("vagrant::config::vm::provisioner") @logger.debug("Provisioner defined: #{name}") - @config = nil - @name = name + @config = nil + @invalid = false + @name = name # Attempt to find the configuration class for this provider # if it exists and load the configuration. config_class = Vagrant.plugin("2").manager.provisioner_configs[@name] if !config_class + @invalid = true @logger.info("Provisioner config for '#{@name}' not found. Ignoring config.") return end @@ -35,6 +37,14 @@ module VagrantPlugins block.call(@config) if block @config.finalize! end + + # Returns whether the provisioner used was invalid or not. A provisioner + # is invalid if it can't be found. + # + # @return [Boolean] + def invalid? + @invalid + end end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a450702d2..6d233a9e6 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -472,15 +472,13 @@ en: Forwarded port '%{host}' (host port) is declared multiple times network_fp_requires_ports: |- Forwarded port definitions require a "host" and "guest" value + provisioner_not_found: |- + The '%{name}' provisioner could not be found. shared_folder_hostpath_missing: |- The host path of the shared folder is missing: %{path} shared_folder_nfs_owner_group: |- Shared folder that have NFS enabled do no support owner/group attributes. Host path: %{path} - provisioner_not_found: "The provisioner '%{shortcut}' doesn't exist." - provisioner_invalid_class: |- - The provisioner '%{shortcut}' must inherit from - `Vagrant::Plugin::V1::Provisioner`." #------------------------------------------------------------------------------- # Translations for commands. e.g. `vagrant x`