diff options
| author | Jack Nagel | 2013-04-13 17:40:12 -0500 | 
|---|---|---|
| committer | Jack Nagel | 2013-04-13 17:40:12 -0500 | 
| commit | 563d8be6bde6eaddcf4eb8d4fb9a10ed0af7ddb7 (patch) | |
| tree | 26d2ddf590ec47e3a51ebd056863a5d5e5aa9c8f /Library/Homebrew/exceptions.rb | |
| parent | 5ba5e215363d0f4737f9004f6e699a2b18eb0761 (diff) | |
| download | homebrew-563d8be6bde6eaddcf4eb8d4fb9a10ed0af7ddb7.tar.bz2 | |
Improved formula attribute validation
The initializer for Formula does a number of validations, but it does
them in a weird order, and some attributes aren't validated under
certain circumstances. This became even more of a mess when most
software package attributes were moved into the SoftwareSpec class.
This commit removes the last vestiges of storing these attributes as
instance variables. In particular, it eliminates #set_instance_variable
and #validate_variable, replacing them with methods that operate on
SoftwareSpec instances, and generate more useful errors.
Doing these validations unconditionally in the initializer means we bail
out much earlier if the formula has invalid attributes or is not fully
specified, and no longer need to validate in #prefix.
Technically we don't need to validate in #brew either, but we continue
to do so anyway as a safety measure, and because we cannot enforce calls
to super in subclasses.
Diffstat (limited to 'Library/Homebrew/exceptions.rb')
| -rw-r--r-- | Library/Homebrew/exceptions.rb | 11 | 
1 files changed, 11 insertions, 0 deletions
| diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index d57f5ddc3..b5299c038 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -22,6 +22,17 @@ class NoSuchKegError < RuntimeError    end  end +class FormulaValidationError < StandardError +  attr_reader :attr + +  def initialize(attr, value) +    @attr = attr +    msg = "invalid attribute: #{attr}" +    msg << " (#{value.inspect})" unless value.empty? +    super msg +  end +end +  class FormulaUnavailableError < RuntimeError    attr_reader :name    attr_accessor :dependent | 
