diff --git a/lib/vagrant/util/downloader.rb b/lib/vagrant/util/downloader.rb index d9eace0c1..285f83b75 100644 --- a/lib/vagrant/util/downloader.rb +++ b/lib/vagrant/util/downloader.rb @@ -292,11 +292,21 @@ module Vagrant # show an error message. if result.exit_code != 0 @logger.warn("Downloader exit code: #{result.exit_code}") - parts = result.stderr.split(/\n*curl:\s+\(\d+\)\s*/, 2) - parts[1] ||= "" - raise Errors::DownloaderError, - code: result.exit_code, - message: parts[1].chomp + check = result.stderr.match(/\n*curl:\s+\((?\d+)\)\s*(?.*)$/) + if check && check[:code] == "416" + # All good actually. 416 means there is no more bytes to download + @logger.warn("Downloader got a 416, but is likely fine. Continuing on...") + else + if !check + err_msg = result.stderr + else + err_msg = check[:error] + end + + raise Errors::DownloaderError, + code: result.exit_code, + message: err_msg + end end result diff --git a/test/unit/vagrant/util/downloader_test.rb b/test/unit/vagrant/util/downloader_test.rb index 772412fbc..b335fe685 100644 --- a/test/unit/vagrant/util/downloader_test.rb +++ b/test/unit/vagrant/util/downloader_test.rb @@ -41,6 +41,20 @@ describe Vagrant::Util::Downloader do context "with a bad exit status" do let(:exit_code) { 1 } + let(:subprocess_result_416) do + double("subprocess_result").tap do |result| + allow(result).to receive(:exit_code).and_return(exit_code) + allow(result).to receive(:stderr).and_return("curl: (416) The download is fine") + end + end + + it "continues on if a 416 was received" do + expect(Vagrant::Util::Subprocess).to receive(:execute). + with("curl", *curl_options). + and_return(subprocess_result_416) + + expect(subject.download!).to be(true) + end it "raises an exception" do expect(Vagrant::Util::Subprocess).to receive(:execute).