Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 156082a627fa05057c934c8704166f9efa6f4163 1 parent 79ac8e2
@kpumuk authored
View
1  chef-expander/lib/chef/expander/solrizer.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
View
16 chef-expander/spec/unit/solrizer_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.