(#7886) Add tests and simplify code for continuing on 416
This commit is contained in:
parent
f1993dfa19
commit
67c3f866dd
|
@ -292,14 +292,20 @@ 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] ||= ""
|
||||
if parts[1].include? "416"
|
||||
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: parts[1].chomp
|
||||
message: err_msg
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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).
|
||||
|
|
Loading…
Reference in New Issue