diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index b8c5d4c622..99745cdb8b 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -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 diff --git a/Library/Homebrew/upgrade.rb b/Library/Homebrew/upgrade.rb index 8f783f079d..acd654e08e 100644 --- a/Library/Homebrew/upgrade.rb +++ b/Library/Homebrew/upgrade.rb @@ -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|