diff --git a/CHANGELOG.md b/CHANGELOG.md index 205204205..20f02643f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ BUG FIXES: - core: Adding a box by path in Cygwin on Windos works. [GH-3132] - core: PowerShell scripts work when they're in a directory with spaces. [GH-3100] + - core: If you add a box path that doesn't exist, error earlier. [GH-3091] - guests/darwin: Fix an exception when configuring networks. [GH-3143] - hosts/linux: Unusual sed delimiter to avoid conflicts. [GH-3167] - providers/virtualbox: Make more internal interactions with VBoxManage diff --git a/lib/vagrant/action/builtin/box_add.rb b/lib/vagrant/action/builtin/box_add.rb index aeb27779c..588ada093 100644 --- a/lib/vagrant/action/builtin/box_add.rb +++ b/lib/vagrant/action/builtin/box_add.rb @@ -314,6 +314,9 @@ module Vagrant box_url = download(url, env, show_url: show_url) break rescue Errors::DownloaderError => e + # If we don't have multiple URLs, just raise the error + raise if urls.length == 1 + env[:ui].error(I18n.t( "vagrant.box_download_error", message: e.message)) box_url = nil diff --git a/test/unit/vagrant/action/builtin/box_add_test.rb b/test/unit/vagrant/action/builtin/box_add_test.rb index a1e479865..584a9c95e 100644 --- a/test/unit/vagrant/action/builtin/box_add_test.rb +++ b/test/unit/vagrant/action/builtin/box_add_test.rb @@ -164,6 +164,19 @@ describe Vagrant::Action::Builtin::BoxAdd do to raise_error(Vagrant::Errors::BoxChecksumMismatch) end + it "raises an error if the box path doesn't exist" do + box_path = iso_env.box2_file(:virtualbox) + + env[:box_name] = "foo" + env[:box_url] = box_path.to_s + "nope" + + box_collection.should_receive(:add).never + app.should_receive(:call).never + + expect { subject.call(env) }. + to raise_error(Vagrant::Errors::DownloaderError) + end + it "force adds if exists and specified" do box_path = iso_env.box2_file(:virtualbox)