Skip to content

Commit 72855d8

Browse files
authored
Merge pull request #21595 from Homebrew/fix-21582
bottle_specification: throw exception instead of panicking to be able to catch it
2 parents 5a94ef2 + 558c121 commit 72855d8

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

Library/Homebrew/bottle_specification.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,22 @@ def tag?(tag, no_older_versions: false)
108108
# sha256 cellar: :any_skip_relocation, big_sur: "69489ae397e4645..."
109109
# sha256 cellar: :any, catalina: "449de5ea35d0e94..."
110110
# end
111-
sig { params(hash: T::Hash[Symbol, T.any(String, Symbol)]).void }
111+
sig { params(hash: T::Hash[T.any(Symbol, String), T.any(String, Symbol)]).void }
112112
def sha256(hash)
113113
sha256_regex = /^[a-f0-9]{64}$/i
114114

115115
# find new `sha256 big_sur: "69489ae397e4645..."` format
116116
tag, digest = hash.find do |key, value|
117+
# Don't use `odie` in this case. We want to be able to catch this exception
118+
# in runtime when getting committed version info in formula auditor
119+
raise LegacyDSLError.new(:sha256, hash) if key.is_a?(String) && key.match?(sha256_regex) && value.is_a?(Symbol)
120+
117121
key.is_a?(Symbol) && value.is_a?(String) && value.match?(sha256_regex)
118122
end
119123

120124
odie "Invalid sha256 hash: #{digest}" if !tag || !digest
121125

122-
tag = Utils::Bottles::Tag.from_symbol(tag)
126+
tag = Utils::Bottles::Tag.from_symbol(T.cast(tag, Symbol))
123127

124128
cellar = hash[:cellar] || tag.default_cellar
125129

Library/Homebrew/exceptions.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ def initialize(formula, attr, value)
7777
end
7878
end
7979

80+
class LegacyDSLError < StandardError
81+
attr_reader :attr
82+
83+
def initialize(attr, value)
84+
@attr = attr
85+
super "A legacy DSL was used: #{attr} (#{value.inspect})"
86+
end
87+
end
88+
8089
class FormulaSpecificationError < StandardError; end
8190

8291
# Raised when a deprecated method is used.

Library/Homebrew/formula_auditor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ def committed_version_info(formula: @formula)
12181218
origin_head_version_info[:version_scheme] ||= previous_version_info[:version_scheme]
12191219
origin_head_version_info[:compatibility_version] ||= previous_version_info[:compatibility_version]
12201220
end
1221-
rescue MacOSVersion::Error
1221+
rescue MacOSVersion::Error, LegacyDSLError
12221222
break
12231223
end
12241224

Library/Homebrew/formula_versions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class FormulaVersions
1212
include Utils::Output::Mixin
1313

1414
IGNORED_EXCEPTIONS = [
15-
ArgumentError, NameError, SyntaxError, TypeError,
15+
ArgumentError, NameError, SyntaxError, TypeError, LegacyDSLError,
1616
FormulaSpecificationError, FormulaValidationError,
1717
ErrorDuringExecution, LoadError, MethodDeprecatedError
1818
].freeze

0 commit comments

Comments
 (0)