Merge pull request #9729 from briancain/dont-raise-416

Don't raise error if response is HTTP 416
This commit is contained in:
Brian Cain 2018-04-25 14:10:26 -07:00 committed by GitHub
commit 18f8c305ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View File

@ -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+\((?<code>\d+)\)\s*(?<error>.*)$/)
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

View File

@ -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).