Permalink
Browse files

Fixed error occurred when Solrizer parses invalid JSON

Since log always returns true, parse generates error "undefined method `[]' for true:TrueClass" when invalid JSON string passed
  • Loading branch information...
1 parent 79ac8e2 commit 156082a627fa05057c934c8704166f9efa6f4163 @kpumuk committed Oct 5, 2011
Showing with 17 additions and 0 deletions.
  1. +1 −0 chef-expander/lib/chef/expander/solrizer.rb
  2. +16 −0 chef-expander/spec/unit/solrizer_spec.rb
@@ -108,6 +108,7 @@ def parse(serialized_object)
Yajl::Parser.parse(serialized_object)
rescue Yajl::ParseError
log.error { "cannot index object because it is invalid JSON: #{serialized_object}" }
+ nil
end
def run
@@ -28,6 +28,22 @@
describe Expander::Solrizer do
SEP = "__=__"
+ describe "when created with invalid JSON" do
+ before do
+ @log_stream = StringIO.new
+ Expander::Solrizer::LOGGER.init(@log_stream)
+ @solrizer = Expander::Solrizer.new('{!"action":"delete"}') { :no_op }
+ end
+
+ it "logs error info" do
+ @log_stream.string.should =~ /invalid JSON/
+ end
+
+ it "skips invalid request" do
+ @solrizer.action.should == "skip"
+ end
+ end
+
describe "when created with an add request" do
before do
@now = Time.now.utc.to_i

0 comments on commit 156082a

Please sign in to comment.