upgrade: raise error if developer and there are cyclic dependencies

This commit is contained in:
fn ⌃ ⌥ 2021-09-12 07:56:37 -07:00
parent 0c3e49092c
commit c0795b5029
2 changed files with 11 additions and 2 deletions

View File

@ -758,3 +758,13 @@ class ShebangDetectionError < RuntimeError
super "Cannot detect #{type} shebang: #{reason}."
end
end
# Raised when one or more formulae have cyclic dependencies.
class CyclicDependencyError < RuntimeError
def initialize(strongly_connected_components)
super <<~EOS
The following packages contain cyclic dependencies:
#{strongly_connected_components.select { |packages| packages.count > 1 }.map(&:to_sentence).join("\n ")}
EOS
end
end

View File

@ -47,8 +47,7 @@ module Homebrew
begin
formulae_to_install = dependency_graph.tsort & formulae_to_install
rescue TSort::Cyclic
# Failed to sort formulae topologically because there are cyclic
# dependencies. Let FormulaInstaller handle it.
raise CyclicDependencyError, dependency_graph.strongly_connected_components if Homebrew::EnvConfig.developer?
end
formula_installers = formulae_to_install.map do |formula|