From 60ab6b86e9f78c5d2cde1d4cd89963ba0b2dedf0 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 19 May 2021 13:15:33 +0100 Subject: [PATCH] software_spec: improve bad manifest error message. Let's complain immediately after fetching if there's something wrong and improve the error message to make it clearer what's going on. Inspired by #76336. --- Library/Homebrew/software_spec.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 22cfe6589b..5b7afa1901 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -347,8 +347,20 @@ class Bottle end def fetch_tab + return if github_packages_manifest_resource.blank? + # a checksum is used later identifying the correct tab but we do not have the checksum for the manifest/tab - github_packages_manifest_resource&.fetch(verify_download_integrity: false) + github_packages_manifest_resource.fetch(verify_download_integrity: false) + + begin + JSON.parse(github_packages_manifest_resource.cached_download.read) + rescue JSON::ParserError + raise DownloadError.new( + github_packages_manifest_resource, + RuntimeError.new("The downloaded GitHub Packages manifest was corrupted or modified (it is not valid JSON):"\ + "\n#{github_packages_manifest_resource.cached_download}"), + ) + end rescue DownloadError raise unless fallback_on_error @@ -363,7 +375,8 @@ class Bottle json = begin JSON.parse(manifest_json) rescue JSON::ParserError - raise ArgumentError, "Couldn't parse manifest JSON." + raise "The downloaded GitHub Packages manifest was corrupted or modified (it is not valid JSON): "\ + "\n#{github_packages_manifest_resource.cached_download}" end manifests = json["manifests"]