Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Removed usage of caller() in exceptions
Browse files Browse the repository at this point in the history
* Thought I was being clever showing the error messages on the line
  where I think they occured, often I needed to know specifically where
  the exception was thrown from to see what the conditions were that
  triggered the exception.
  • Loading branch information
Dan Kubb committed Feb 14, 2009
1 parent 8f39b43 commit 75d3f50
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 41 deletions.
10 changes: 5 additions & 5 deletions lib/dm-core/associations.rb
Expand Up @@ -196,13 +196,13 @@ def assert_valid_options(options)
assert_kind_of 'options[:max]', options[:max], Integer, n.class

if options[:min] == n && options[:max] == n
raise ArgumentError, 'Cardinality may not be n..n. The cardinality specifies the min/max number of results from the association', caller(1)
raise ArgumentError, 'Cardinality may not be n..n. The cardinality specifies the min/max number of results from the association'
elsif options[:min] > options[:max]
raise ArgumentError, "Cardinality min (#{options[:min]}) cannot be larger than the max (#{options[:max]})", caller(1)
raise ArgumentError, "Cardinality min (#{options[:min]}) cannot be larger than the max (#{options[:max]})"
elsif options[:min] < 0
raise ArgumentError, "Cardinality min much be greater than or equal to 0, but was #{options[:min]}", caller(1)
raise ArgumentError, "Cardinality min much be greater than or equal to 0, but was #{options[:min]}"
elsif options[:max] < 1
raise ArgumentError, "Cardinality max much be greater than or equal to 1, but was #{options[:max]}", caller(1)
raise ArgumentError, "Cardinality max much be greater than or equal to 1, but was #{options[:max]}"
end
end

Expand Down Expand Up @@ -239,7 +239,7 @@ def assert_valid_options(options)
end

if options.key?(:limit)
raise ArgumentError, '+options[:limit]+ should not be specified on a relationship', caller(1)
raise ArgumentError, '+options[:limit]+ should not be specified on a relationship'
end
end

Expand Down
12 changes: 6 additions & 6 deletions lib/dm-core/property.rb
Expand Up @@ -354,7 +354,7 @@ def field(repository_name = nil)
warn "Passing in +repository_name+ to #{self.class}#field is deprecated: #{caller[0]}"

if repository_name != self.repository_name
raise ArgumentError, "Mismatching +repository_name+ with #{self.class}#repository_name (#{repository_name.inspect} != #{self.repository_name.inspect})", caller
raise ArgumentError, "Mismatching +repository_name+ with #{self.class}#repository_name (#{repository_name.inspect} != #{self.repository_name.inspect})"
end
end

Expand Down Expand Up @@ -767,7 +767,7 @@ def initialize(model, name, type, options = {})
end

unless TYPES.include?(type) || (Type > type && TYPES.include?(type.primitive))
raise ArgumentError, "+type+ was #{type.inspect}, which is not a supported type", caller
raise ArgumentError, "+type+ was #{type.inspect}, which is not a supported type"
end

@repository_name = model.repository.name
Expand Down Expand Up @@ -827,7 +827,7 @@ def initialize(model, name, type, options = {})

def assert_valid_options(options)
if (unknown = options.keys - PROPERTY_OPTIONS).any?
raise ArgumentError, "options #{unknown.map { |o| o.inspect }.join(' and ')} are unknown", caller(1)
raise ArgumentError, "options #{unknown.map { |o| o.inspect }.join(' and ')} are unknown"
end

options.each do |key,value|
Expand All @@ -837,12 +837,12 @@ def assert_valid_options(options)

when :default
if value.nil?
raise ArgumentError, "options[#{key.inspect}] must not be nil", caller(1)
raise ArgumentError, "options[#{key.inspect}] must not be nil"
end

when :serial, :key, :nullable, :unique, :lazy, :auto_validation
unless value == true || value == false
raise ArgumentError, "options[#{key.inspect}] must be either true or false", caller(1)
raise ArgumentError, "options[#{key.inspect}] must be either true or false"
end

when :index, :unique_index
Expand All @@ -858,7 +858,7 @@ def assert_valid_options(options)
assert_kind_of "options[#{key.inspect}]", value, Symbol

unless VISIBILITY_OPTIONS.include?(value)
raise ArgumentError, "options[#{key.inspect}] must be #{VISIBILITY_OPTIONS.join(' or ')}", caller(1)
raise ArgumentError, "options[#{key.inspect}] must be #{VISIBILITY_OPTIONS.join(' or ')}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dm-core/property_set.rb
Expand Up @@ -92,7 +92,7 @@ def lazy_context(name)

def lazy_load_context(names)
if names.kind_of?(Array) && names.empty?
raise ArgumentError, '+names+ cannot be empty', caller
raise ArgumentError, '+names+ cannot be empty'
end

result = []
Expand Down
58 changes: 29 additions & 29 deletions lib/dm-core/query.rb
Expand Up @@ -573,31 +573,31 @@ def assert_valid_fields(fields, unique)
assert_kind_of 'options[:fields]', fields, Array

if fields.empty? && unique == false
raise ArgumentError, '+options[:fields]+ should not be empty if +options[:unique]+ is false', caller(3)
raise ArgumentError, '+options[:fields]+ should not be empty if +options[:unique]+ is false'
end

fields.each do |field|
case field
when Property
unless @properties.include?(field)
raise ArgumentError, "+options[:field]+ entry #{field.name.inspect} does not map to a property", caller(3)
raise ArgumentError, "+options[:field]+ entry #{field.name.inspect} does not map to a property"
end

# TODO: mix-in Operator validation for fields in dm-aggregates
#when Operator
# target = field.target
#
# unless target.kind_of?(Property) && @properties.include?(target)
# raise ArgumentError, "+options[:fields]+ entry #{target.inspect} does not map to a property", caller(3)
# raise ArgumentError, "+options[:fields]+ entry #{target.inspect} does not map to a property"
# end

when Symbol, String
unless @properties.named?(field)
raise ArgumentError, "+options[:fields]+ entry #{field.inspect} does not map to a property", caller(3)
raise ArgumentError, "+options[:fields]+ entry #{field.inspect} does not map to a property"
end

else
raise ArgumentError, "+options[:fields]+ entry #{field.inspect} of an unsupported object #{field.class}", caller(3)
raise ArgumentError, "+options[:fields]+ entry #{field.inspect} of an unsupported object #{field.class}"
end
end
end
Expand All @@ -608,24 +608,24 @@ def assert_valid_links(links)
assert_kind_of 'options[:links]', links, Array

if links.empty?
raise ArgumentError, '+options[:links]+ should not be empty', caller(3)
raise ArgumentError, '+options[:links]+ should not be empty'
end

links.each do |link|
case link
when Associations::Relationship
# TODO: figure out how to validate links from other models
#unless @relationships.value?(link)
# raise ArgumentError, "+options[:links]+ entry #{link.name.inspect} does not map to a relationship", caller(3)
# raise ArgumentError, "+options[:links]+ entry #{link.name.inspect} does not map to a relationship"
#end

when Symbol, String
unless @relationships.key?(link.to_sym)
raise ArgumentError, "+options[:links]+ entry #{link.inspect} does not map to a relationship", caller(3)
raise ArgumentError, "+options[:links]+ entry #{link.inspect} does not map to a relationship"
end

else
raise ArgumentError, "+options[:links]+ entry #{link.inspect} of an unsupported object #{link.class}", caller(3)
raise ArgumentError, "+options[:links]+ entry #{link.inspect} of an unsupported object #{link.class}"
end
end
end
Expand All @@ -636,7 +636,7 @@ def assert_valid_conditions(conditions)
assert_kind_of 'options[:conditions]', conditions, Hash, Array

if conditions.empty?
raise ArgumentError, '+options[:conditions]+ should not be empty', caller(3)
raise ArgumentError, '+options[:conditions]+ should not be empty'
end
end

Expand All @@ -646,11 +646,11 @@ def assert_valid_offset(offset, limit)
assert_kind_of 'options[:offset]', offset, Integer

unless offset >= 0
raise ArgumentError, "+options[:offset]+ must be greater than or equal to 0, but was #{offset.inspect}", caller(3)
raise ArgumentError, "+options[:offset]+ must be greater than or equal to 0, but was #{offset.inspect}"
end

if offset > 0 && limit.nil?
raise ArgumentError, '+options[:offset]+ cannot be greater than 0 if limit is not specified', caller(3)
raise ArgumentError, '+options[:offset]+ cannot be greater than 0 if limit is not specified'
end
end

Expand All @@ -660,7 +660,7 @@ def assert_valid_limit(limit)
assert_kind_of 'options[:limit]', limit, Integer

unless limit >= 1
raise ArgumentError, "+options[:limit]+ must be greater than or equal to 1, but was #{limit.inspect}", caller(3)
raise ArgumentError, "+options[:limit]+ must be greater than or equal to 1, but was #{limit.inspect}"
end
end

Expand All @@ -670,48 +670,48 @@ def assert_valid_order(order, fields)
assert_kind_of 'options[:order]', order, Array

if order.empty? && fields && fields.any? { |p| !p.kind_of?(Operator) }
raise ArgumentError, '+options[:order]+ should not be empty if +options[:fields] contains a non-operator', caller(3)
raise ArgumentError, '+options[:order]+ should not be empty if +options[:fields] contains a non-operator'
end

order.each do |order|
case order
when Direction
unless @properties.include?(order.property)
raise ArgumentError, "+options[:order]+ entry #{order.property.name.inspect} does not map to a property", caller(3)
raise ArgumentError, "+options[:order]+ entry #{order.property.name.inspect} does not map to a property"
end

when Property
unless @properties.include?(order)
raise ArgumentError, "+options[:order]+ entry #{order.name.inspect} does not map to a property", caller(3)
raise ArgumentError, "+options[:order]+ entry #{order.name.inspect} does not map to a property"
end

when Operator
unless order.operator == :asc || order.operator == :desc
raise ArgumentError, "+options[:order]+ entry #{order.inspect} used an invalid operator #{order.operator}", caller(3)
raise ArgumentError, "+options[:order]+ entry #{order.inspect} used an invalid operator #{order.operator}"
end

case target = order.target
when Property
unless @properties.include?(target)
raise ArgumentError, "+options[:order]+ entry #{target.inspect} does not map to a property", caller(3)
raise ArgumentError, "+options[:order]+ entry #{target.inspect} does not map to a property"
end

when Symbol, String
unless @properties.named?(target)
raise ArgumentError, "+options[:order]+ entry #{target.inspect} does not map to a property", caller(3)
raise ArgumentError, "+options[:order]+ entry #{target.inspect} does not map to a property"
end

else
raise ArgumentError, "+options[:order]+ entry #{order.inspect} does not contain a Property, Symbol or String, but was #{target.class}", caller(3)
raise ArgumentError, "+options[:order]+ entry #{order.inspect} does not contain a Property, Symbol or String, but was #{target.class}"
end

when Symbol, String
unless @properties.named?(order)
raise ArgumentError, "+options[:order]+ entry #{order.inspect} does not map to a property", caller(3)
raise ArgumentError, "+options[:order]+ entry #{order.inspect} does not map to a property"
end

else
raise ArgumentError, "+options[:order]+ entry #{order.inspect} of an unsupported object #{order.class}", caller(3)
raise ArgumentError, "+options[:order]+ entry #{order.inspect} of an unsupported object #{order.class}"
end
end
end
Expand All @@ -720,19 +720,19 @@ def assert_valid_order(order, fields)
# @api private
def assert_valid_boolean(name, value)
if value != true && value != false
raise ArgumentError, "+#{name}+ should be true or false, but was #{value.inspect}", caller(3)
raise ArgumentError, "+#{name}+ should be true or false, but was #{value.inspect}"
end
end

# TODO: document this
# @api private
def assert_valid_other(other)
unless other.repository == repository
raise ArgumentError, "+other+ #{self.class} must be for the #{repository.name} repository, not #{other.repository.name}", caller(2)
raise ArgumentError, "+other+ #{self.class} must be for the #{repository.name} repository, not #{other.repository.name}"
end

unless other.model == model
raise ArgumentError, "+other+ #{self.class} must be for the #{model.name} model, not #{other.model.name}", caller(2)
raise ArgumentError, "+other+ #{self.class} must be for the #{model.name} model, not #{other.model.name}"
end
end

Expand Down Expand Up @@ -852,19 +852,19 @@ def append_condition(subject, bind_value, operator = :eql)

else
# TODO: move into assert_valid_conditions
raise ArgumentError, "Condition type #{subject.inspect} not supported", caller(2)
raise ArgumentError, "Condition type #{subject.inspect} not supported"
end

# TODO: move into assert_valid_conditions
if property.nil?
raise ArgumentError, "Clause #{subject.inspect} does not map to a DataMapper::Property", caller(2)
raise ArgumentError, "Clause #{subject.inspect} does not map to a DataMapper::Property or DataMapper::Associations::Relationship"
end

bind_value = normalize_bind_value(property, bind_value)

# TODO: move into assert_valid_conditions
if operator == :not && bind_value.kind_of?(Array) && bind_value.empty?
raise ArgumentError, "Cannot use 'not' operator with a bind value that is an empty Array for #{property}", caller(2)
raise ArgumentError, "Cannot use 'not' operator with a bind value that is an empty Array for #{property}"
end

@conditions << [ operator, property, bind_value ]
Expand Down Expand Up @@ -931,7 +931,7 @@ def extract_slice_arguments(*args)
end
end

raise ArgumentError, "arguments may be 1 or 2 Integers, or 1 Range object, was: #{args.inspect}", caller(1)
raise ArgumentError, "arguments may be 1 or 2 Integers, or 1 Range object, was: #{args.inspect}"
end

# TODO: document this
Expand Down

0 comments on commit 75d3f50

Please sign in to comment.