Skip to content

Commit

Permalink
- improve validation reporting
Browse files Browse the repository at this point in the history
- check to_f and to_i conversions with :number validation
  • Loading branch information
jordansissel committed Mar 30, 2013
1 parent ae7651a commit 225e52b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/logstash/config/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ def validate_check_parameter_values(params)
else
@logger.error(I18n.t("logstash.agent.configuration.setting_invalid",
:plugin => @plugin_name, :type => @plugin_type,
:value => value, :value_type => config_val))
:setting => key, :value => value, :value_type => config_val,
:note => result))
end
#puts "Result: #{key} / #{result.inspect} / #{success}"
is_valid &&= success
Expand Down Expand Up @@ -348,10 +349,11 @@ def validate_value(value, validator)
result = value.first
when :number
if value.size > 1 # only one value wanted
return false, "Expected number, got #{value.inspect}"
return false, "Expected number, got #{value.inspect} (type #{value.class})"
end
if value.first.to_s.to_f.to_s != value.first.to_s
return false, "Expected number, got #{value.first.inspect}"
if value.first.to_s.to_f.to_s != value.first.to_s \
&& value.first.to_s.to_i.to_s != value.first.to_s
return false, "Expected number, got #{value.first.inspect} (type #{value.first})"
end
result = value.first.to_i
when :boolean
Expand Down
1 change: 1 addition & 0 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ en:
%{type} {
%{plugin} {
# This setting must be a %{value_type}
# %{note}
%{setting} => %{value}
...
}
Expand Down

0 comments on commit 225e52b

Please sign in to comment.