attestation: specialize error when gh is old

See https://github.com/Homebrew/homebrew-core/issues/177384#issuecomment-2263195832.

Signed-off-by: William Woodruff <william@yossarian.net>
This commit is contained in:
William Woodruff 2024-08-01 11:36:36 -04:00
parent d29acdd711
commit e66df8cfb1
No known key found for this signature in database

View File

@ -52,6 +52,12 @@ module Homebrew
# @api private
class GhAuthInvalid < RuntimeError; end
# Raised if the version of `gh` invoked is too old to support
# attestations.
#
# @api private
class GhTooOld < RuntimeError; end
# Returns whether attestation verification is enabled.
#
# @api private
@ -143,6 +149,11 @@ module Homebrew
raise MissingAttestationError, "attestation not found: #{e}" if e.stderr.include?("HTTP 404: Not Found")
if e.stderr.include?("unknown command \"attestation\" for \"gh\"")
raise GhTooOld,
"your version of `gh` is too old; run `brew upgrade gh` to continue"
end
raise InvalidAttestationError, "attestation verification failed: #{e}"
end