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}"
 | 
			
		||||
  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"
 | 
			
		||||
          Formula["perl"].opt_bin/"perl"
 | 
			
		||||
        else
 | 
			
		||||
          raise "Cannot detect Perl shebang: formula does not depend on Perl."
 | 
			
		||||
          raise ShebangDetectionError.new("Perl", "formula does not depend on Perl")
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        Utils::Shebang::RewriteInfo.new(
 | 
			
		||||
 | 
			
		||||
@ -105,8 +105,10 @@ module Language
 | 
			
		||||
      def detected_python_shebang(formula = self)
 | 
			
		||||
        python_deps = formula.deps.map(&:name).grep(/^python(@.*)?$/)
 | 
			
		||||
 | 
			
		||||
        raise "Cannot detect Python shebang: 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
 | 
			
		||||
        raise ShebangDetectionError.new("Python", "formula does not depend on Python") if python_deps.empty?
 | 
			
		||||
        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")
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user