From c3076f0b6923f595f3d70eb849eeb8b0b204da3b Mon Sep 17 00:00:00 2001 From: Martin Afanasjew Date: Sat, 16 Apr 2016 20:58:20 +0200 Subject: [PATCH] formulary: use FormulaClassUnavailableError Present a more helpful error message if a formula file was loaded, but the class(es) therein didn't match the expected formula class name. --- Library/Homebrew/formulary.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 79e4c946bd..28e79c68f8 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -23,8 +23,12 @@ class Formulary begin mod.const_get(class_name) - rescue NameError => e - raise FormulaUnavailableError, name, e.backtrace + rescue NameError => original_exception + class_list = mod.constants. + map { |const_name| mod.const_get(const_name) }. + select { |const| const.is_a?(Class) } + e = FormulaClassUnavailableError.new(name, path, class_name, class_list) + raise e, "", original_exception.backtrace end end