From e66df8cfb1fdc82a61825c02e99822f29c23ac2c Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Thu, 1 Aug 2024 11:36:36 -0400 Subject: [PATCH] attestation: specialize error when `gh` is old See https://github.com/Homebrew/homebrew-core/issues/177384#issuecomment-2263195832. Signed-off-by: William Woodruff --- Library/Homebrew/attestation.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Library/Homebrew/attestation.rb b/Library/Homebrew/attestation.rb index 853643465f..7cc4bce456 100644 --- a/Library/Homebrew/attestation.rb +++ b/Library/Homebrew/attestation.rb @@ -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