From 6bac0a7ab2e591d86dd54e5f635de20bd81b88cb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 21 Oct 2010 17:58:17 -0700 Subject: [PATCH] Better box verification/error messages. --- CHANGELOG.md | 1 + lib/vagrant/config/vm.rb | 4 +++- lib/vagrant/environment.rb | 4 +--- templates/locales/en.yml | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c6709cc9..f43a24855 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.6.7 (unreleased) + - Added validation to verify that a box is specified. - Proper error message when box is not found for `config.vm.box`. [GH-195] - Fix output of `vagrant status` with multi-vm to be correct. [GH-196] diff --git a/lib/vagrant/config/vm.rb b/lib/vagrant/config/vm.rb index c70892237..2a9374e9c 100644 --- a/lib/vagrant/config/vm.rb +++ b/lib/vagrant/config/vm.rb @@ -104,8 +104,10 @@ module Vagrant end end + errors.add(I18n.t("vagrant.config.vm.box_missing")) if !box + errors.add(I18n.t("vagrant.config.vm.box_not_found", :name => box)) if box && !box_url && !env.box errors.add(I18n.t("vagrant.config.vm.boot_mode_invalid")) if ![:vrdp, :gui].include?(boot_mode.to_sym) - errors.add(I18n.t("vagrant.config.vm.base_mac_invalid")) if !base_mac + errors.add(I18n.t("vagrant.config.vm.base_mac_invalid")) if env.box && !base_mac end end end diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 91d4b5ee9..40824c43a 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -121,9 +121,7 @@ module Vagrant # # @return [Box] def box - result = boxes.find(config.vm.box) - raise Errors::BoxNotFound, :name => config.vm.box if vm && !result - result + boxes.find(config.vm.box) end # Returns the VMs associated with this environment. diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a613ac95a..b5786955c 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -115,6 +115,8 @@ en: vm: base_mac_invalid: "Base MAC address for eth0/NAT must be set. Contact box maintainer for more information." boot_mode_invalid: "Boot mode must be one of: vrdp or gui" + box_missing: "A box must be specified." + box_not_found: "The box '%{name}' could not be found." shared_folder_hostpath_missing: "Shared folder host path for '%{name}' doesn't exist: %{path}" #-------------------------------------------------------------------------------