diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb index 1da870a39..4baca3a4f 100644 --- a/lib/vagrant/box.rb +++ b/lib/vagrant/box.rb @@ -103,6 +103,9 @@ module Vagrant opts = { headers: ["Accept: application/json"] } Util::Downloader.new(url, tf.path, **opts).download! BoxMetadata.new(File.open(tf.path, "r")) + rescue Errors::DownloaderError => e + raise Errors::BoxMetadataDownloadError, + message: e.extra_data[:message] end # Checks if the box has an update and returns the metadata, version, diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index d89b61fa2..a0ce3bb13 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -168,6 +168,10 @@ module Vagrant error_key(:box_metadata_corrupted) end + class BoxMetadataDownloadError < VagrantError + error_key(:box_metadata_download_error) + end + class BoxMetadataFileNotFound < VagrantError error_key(:box_metadata_file_not_found) end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index e73ce8b0c..360f5205a 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -382,6 +382,11 @@ en: The metadata associated with the box '%{name}' appears corrupted. This is most often caused by a disk issue or system crash. Please remove the box, re-add it, and try again. + box_metadata_download_error: |- + There was an error while downloading the metadata for this box. + The error message is shown below: + + %{message} box_metadata_file_not_found: |- The "metadata.json" file for the box '%{name}' was not found. Boxes require this file in order for Vagrant to determine the diff --git a/test/unit/vagrant/box_test.rb b/test/unit/vagrant/box_test.rb index baa3e09cf..4d40bb9ce 100644 --- a/test/unit/vagrant/box_test.rb +++ b/test/unit/vagrant/box_test.rb @@ -219,6 +219,16 @@ describe Vagrant::Box do expect(result.name).to eq("foo") expect(result.description).to eq("bar") end + + it "raises an error if the download failed" do + dl = double("downloader") + Vagrant::Util::Downloader.stub(new: dl) + dl.should_receive(:download!).and_raise( + Vagrant::Errors::DownloaderError.new(message: "foo")) + + expect { subject.load_metadata }. + to raise_error(Vagrant::Errors::BoxMetadataDownloadError) + end end describe "destroying" do