Skip to content

Commit

Permalink
Merge pull request #18334 from Homebrew/NoSuchKegFromTapError
Browse files Browse the repository at this point in the history
  • Loading branch information
carlocab authored Sep 16, 2024
2 parents 2985b16 + eb93d84 commit 076c4e0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/cli/named_args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def resolve_kegs(name)
keg.tab.tap == requested_tap
end

raise NoSuchKegFromTapError.new(requested_formula, requested_tap) if kegs.none?
raise NoSuchKegError.new(requested_formula, tap: requested_tap) if kegs.none?
end

raise NoSuchKegError, name if kegs.none?
Expand Down
17 changes: 4 additions & 13 deletions Library/Homebrew/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,14 @@ class NotAKegError < RuntimeError; end

# Raised when a keg doesn't exist.
class NoSuchKegError < RuntimeError
attr_reader :name

def initialize(name)
@name = name
super "No such keg: #{HOMEBREW_CELLAR}/#{name}"
end
end

# Raised when a keg from a specific tap doesn't exist.
class NoSuchKegFromTapError < RuntimeError
attr_reader :name, :tap

sig { params(name: String, tap: Tap).void }
def initialize(name, tap)
def initialize(name, tap: nil)
@name = name
@tap = tap
super "No such keg: #{HOMEBREW_CELLAR}/#{name} from tap #{tap}"
message = "No such keg: #{HOMEBREW_CELLAR}/#{name}"
message += " from tap #{tap}" if tap
super message
end
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cli/named_args_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def setup_unredable_cask(name)
it "raises an error if there is no tap match" do
stub_formula_loader bar, "other/tap/bar"

expect { described_class.new("other/tap/bar").to_kegs }.to raise_error(NoSuchKegFromTapError)
expect { described_class.new("other/tap/bar").to_kegs }.to raise_error(NoSuchKegError, %r{from tap other/tap})
end
end
end
Expand Down
18 changes: 10 additions & 8 deletions Library/Homebrew/test/exceptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
end
end

describe NoSuchKegFromTapError do
subject(:error) { described_class.new("foo", tap) }
describe NoSuchKegError do
context "without a tap" do
subject(:error) { described_class.new("foo") }

let(:tap) { instance_double(Tap, to_s: "u/r") }
it(:to_s) { expect(error.to_s).to eq("No such keg: #{HOMEBREW_CELLAR}/foo") }
end

it(:to_s) { expect(error.to_s).to eq("No such keg: #{HOMEBREW_CELLAR}/foo from tap u/r") }
end
context "with a tap" do
subject(:error) { described_class.new("foo", tap:) }

describe NoSuchKegError do
subject(:error) { described_class.new("foo") }
let(:tap) { instance_double(Tap, to_s: "u/r") }

it(:to_s) { expect(error.to_s).to eq("No such keg: #{HOMEBREW_CELLAR}/foo") }
it(:to_s) { expect(error.to_s).to eq("No such keg: #{HOMEBREW_CELLAR}/foo from tap u/r") }
end
end

describe FormulaValidationError do
Expand Down

0 comments on commit 076c4e0

Please sign in to comment.