Merge pull request #14497 from Rylan12/fix-api-fallback

Fix JSON file download failure fallback
This commit is contained in:
Mike McQuaid 2023-02-04 13:47:09 +01:00 committed by GitHub
commit 7b3756a29f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,15 +45,17 @@ module Homebrew
curl_args.prepend("--time-cond", target) if target.exist? && !target.empty?
begin
# Disable retries here, we handle them ourselves below.
Utils::Curl.curl_download(*curl_args, to: target, max_time: JSON_API_MAX_TIME, retries: 0)
begin
# Disable retries here, we handle them ourselves below.
Utils::Curl.curl_download(*curl_args, to: target, max_time: JSON_API_MAX_TIME, retries: 0)
rescue ErrorDuringExecution
raise unless target.exist?
raise if target.empty?
opoo "#{target.basename}: update failed, falling back to cached version."
end
JSON.parse(target.read)
rescue ErrorDuringExecution
raise unless target.exist?
raise if target.empty?
opoo "#{target.basename}: update failed, falling back to cached version."
rescue JSON::ParserError
target.unlink
retry_count += 1