Skip to content

Commit 08e0719

Browse files
committed
move ValidationFailed into chef's exception hierarchy
1 parent 3fe2bc7 commit 08e0719

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

‎chef/lib/chef/exceptions.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ class CouchDBNotFound < RuntimeError; end
3636
classPrivateKeyMissing < RuntimeError;end
3737
classCannotWritePrivateKey < RuntimeError;end
3838
classRoleNotFound < RuntimeError;end
39+
40+
classValidationFailed < ArgumentError;end
3941
end
4042
end

‎chef/lib/chef/mixin/params_validate.rb‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
# limitations under the License.
1717

1818
classChef
19-
classValidationFailed < ArgumentError
20-
end
2119

2220
moduleMixin
2321
moduleParamsValidate
@@ -112,7 +110,7 @@ def _pv_required(opts, key, is_required=true)
112110
(opts.has_key?(key.to_sym) && !opts[key.to_sym].nil?)
113111
true
114112
else
115-
raiseValidationFailed,"Required argument #{key} is missing!"
113+
raiseExceptions::ValidationFailed,"Required argument #{key} is missing!"
116114
end
117115
end
118116
end
@@ -125,7 +123,7 @@ def _pv_equal_to(opts, key, to_be)
125123
passes=trueifvalue == tb
126124
end
127125
unlesspasses
128-
raiseValidationFailed,"Option #{key} must be equal to one of: #{to_be.join(", ")}! You passed #{value.inspect}."
126+
raiseExceptions::ValidationFailed,"Option #{key} must be equal to one of: #{to_be.join(", ")}! You passed #{value.inspect}."
129127
end
130128
end
131129
end
@@ -139,7 +137,7 @@ def _pv_kind_of(opts, key, to_be)
139137
passes=trueifvalue.kind_of?(tb)
140138
end
141139
unlesspasses
142-
raiseValidationFailed,"Option #{key} must be a kind of #{to_be}! You passed #{value.inspect}."
140+
raiseExceptions::ValidationFailed,"Option #{key} must be a kind of #{to_be}! You passed #{value.inspect}."
143141
end
144142
end
145143
end
@@ -150,14 +148,14 @@ def _pv_respond_to(opts, key, method_name_list)
150148
unlessvalue.nil?
151149
Array(method_name_list).eachdo |method_name|
152150
unlessvalue.respond_to?(method_name)
153-
raiseValidationFailed,"Option #{key} must have a #{method_name} method!"
151+
raiseExceptions::ValidationFailed,"Option #{key} must have a #{method_name} method!"
154152
end
155153
end
156154
end
157155
end
158156

159157
# Assert that parameter returns false when passed a predicate method.
160-
# For example, :cannot_be => :blank will raise a ValidationFailed
158+
# For example, :cannot_be => :blank will raise a Exceptions::ValidationFailed
161159
# error value.blank? returns a 'truthy' (not nil or false) value.
162160
#
163161
# Note, this will *PASS* if the object doesn't respond to the method.
@@ -169,7 +167,7 @@ def _pv_cannot_be(opts, key, predicate_method_base_name)
169167

170168
ifvalue.respond_to?(predicate_method)
171169
ifvalue.send(predicate_method)
172-
raiseValidationFailed,"Option #{key} cannot be #{predicate_method_base_name}"
170+
raiseExceptions::ValidationFailed,"Option #{key} cannot be #{predicate_method_base_name}"
173171
end
174172
end
175173
end
@@ -195,7 +193,7 @@ def _pv_regex(opts, key, regex)
195193
end
196194
end
197195
unlesspasses
198-
raiseValidationFailed,"Option #{key}'s value #{value} does not match regular expression #{regex.to_s}"
196+
raiseExceptions::ValidationFailed,"Option #{key}'s value #{value} does not match regular expression #{regex.to_s}"
199197
end
200198
end
201199
end
@@ -207,7 +205,7 @@ def _pv_callbacks(opts, key, callbacks)
207205
ifvalue != nil
208206
callbacks.eachdo |message,zeproc|
209207
ifzeproc.call(value) != true
210-
raiseValidationFailed,"Option #{key}'s value #{value}#{message}!"
208+
raiseExceptions::ValidationFailed,"Option #{key}'s value #{value}#{message}!"
211209
end
212210
end
213211
end

‎chef/spec/unit/mixin/params_validate_spec.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def music(is_good=true)
334334
end.should_notraise_error
335335
lambdado
336336
@vo.validate({:not_blank=>""},{:not_blank=>{:cannot_be=>:blank}})
337-
end.shouldraise_error(Chef::ValidationFailed)
337+
end.shouldraise_error(Chef::Exceptions::ValidationFailed)
338338
end
339339

340340
it"should set and return a value, then return the same value"do

‎chef/spec/unit/node_spec.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
end
5656

5757
it"cannot be blank"do
58-
lambda{@node.name("")}.shouldraise_error(Chef::ValidationFailed)
58+
lambda{@node.name("")}.shouldraise_error(Chef::Exceptions::ValidationFailed)
5959
end
6060
end
6161

0 commit comments

Comments
(0)