Raise error if downloading box metadata fails

This commit is contained in:
sophia 2021-02-12 16:16:16 -06:00
parent 81b7d1524b
commit 4b67216d71
2 changed files with 22 additions and 0 deletions

View File

@ -108,6 +108,14 @@ module Vagrant
end
end
is_error = is_metadata_results.find do |b|
b.is_a?(Errors::DownloaderError)
end
if is_error
raise Errors::BoxMetadataDownloadError,
message: is_error.extra_data[:message]
end
is_metadata = is_metadata_results.any? { |b| b === true }
if is_metadata && url.length > 1
raise Errors::BoxAddMetadataMultiURL,

View File

@ -735,6 +735,20 @@ describe Vagrant::Action::Builtin::BoxAdd, :skip_windows, :bsdtar do
end
end
it "raises an error if downloading metadata fails" do
path = Dir::Tmpname.create("vagrant-shorthand-invalid") {}
with_web_server(Pathname.new(path)) do |port|
env[:box_url] = "http://127.0.0.1:#{port}/bad"
expect(box_collection).to receive(:add).never
expect(app).to receive(:call).never
expect { subject.call(env) }.
to raise_error(Vagrant::Errors::BoxMetadataDownloadError)
end
end
it "raises an error if multiple metadata URLs are given" do
box_path = iso_env.box2_file(:virtualbox)
tf = Tempfile.new(["vagrant-box-multi-metadata", ".json"]).tap do |f|