language: raise ShebangDetectionError rather than a generic error
This commit is contained in:
parent
1e567161d1
commit
728bb547a7
@ -729,3 +729,10 @@ class MacOSVersionError < RuntimeError
|
|||||||
super "unknown or unsupported macOS version: #{version.inspect}"
|
super "unknown or unsupported macOS version: #{version.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when `detected_perl_shebang` etc cannot detect the shebang.
|
||||||
|
class ShebangDetectionError < RuntimeError
|
||||||
|
def initialize(type, reason)
|
||||||
|
super "Cannot detect #{type} shebang: #{reason}."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -16,7 +16,7 @@ module Language
|
|||||||
elsif formula.deps.map(&:name).include? "perl"
|
elsif formula.deps.map(&:name).include? "perl"
|
||||||
Formula["perl"].opt_bin/"perl"
|
Formula["perl"].opt_bin/"perl"
|
||||||
else
|
else
|
||||||
raise "Cannot detect Perl shebang: formula does not depend on Perl."
|
raise ShebangDetectionError.new("Perl", "formula does not depend on Perl")
|
||||||
end
|
end
|
||||||
|
|
||||||
Utils::Shebang::RewriteInfo.new(
|
Utils::Shebang::RewriteInfo.new(
|
||||||
|
@ -105,8 +105,10 @@ module Language
|
|||||||
def detected_python_shebang(formula = self)
|
def detected_python_shebang(formula = self)
|
||||||
python_deps = formula.deps.map(&:name).grep(/^python(@.*)?$/)
|
python_deps = formula.deps.map(&:name).grep(/^python(@.*)?$/)
|
||||||
|
|
||||||
raise "Cannot detect Python shebang: formula does not depend on Python." if python_deps.empty?
|
raise ShebangDetectionError.new("Python", "formula does not depend on Python") if python_deps.empty?
|
||||||
raise "Cannot detect Python shebang: formula has multiple Python dependencies." if python_deps.length > 1
|
if python_deps.length > 1
|
||||||
|
raise ShebangDetectionError.new("Python", "formula has multiple Python dependencies")
|
||||||
|
end
|
||||||
|
|
||||||
python_shebang_rewrite_info(Formula[python_deps.first].opt_bin/"python3")
|
python_shebang_rewrite_info(Formula[python_deps.first].opt_bin/"python3")
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user