splunk / splunk-sdk-ruby

Splunk Software Development Kit for Ruby
http://dev.splunk.com
Apache License 2.0
36 stars 21 forks source link

Return an empty array of results rather than throw an exception if the Rest API returns nothing #4

Closed beezly closed 12 years ago

beezly commented 12 years ago

Splunk::Jobs.create_oneshot currently throws a JSON::ParserError if there are no results returned by the REST API.

This commit catches a JSON::ParserError and returns a SearchResult of an empty array for consistency.

ampledata commented 12 years ago

This looks like it contains the same changes as PR #3?

itay commented 12 years ago

Awesome. I actually ran into a similar issue in our JS SDK, but I was looking at the XML output rather than JSON.

One question: would it be possible to detect the REST API returning an empty string and replacing it with "[]"? In JavaScript, for example, I might do something like:

response = response || "[]"

Just wondering if something similar is possible for Ruby (you'll have to excuse my ignorance) :)

itay commented 12 years ago

@ampledata I don't think so - this one contains a code change

beezly commented 12 years ago

@itay it's straight forward to do that, although I think the "empty" response actually contains "\n". If that would be better I'll create a different pull request.

beezly commented 12 years ago

@ampledata my fault. I created the pull request badly for #3. This one is just fixing the "empty result" problem.

itay commented 12 years ago

@beezly you know Ruby better than I do, so you can be the judge of what is more idiomatic. :)

beezly commented 12 years ago

@itay This one can be closed. It got merged as part of #3 because I created the pull request badly :(

Having said that, I think this is a better solution than cleaning up the \n anyway.