ruby-rdf / sparql-client

SPARQL client for Ruby.
http://rubygems.org/gems/sparql-client
The Unlicense
112 stars 58 forks source link

raise error when no suitable rdf reader is found #68

Closed nvdk closed 8 years ago

nvdk commented 8 years ago

Currently sparql-client will silently fail with a nil if no suitable rdf reader is found. This can lead to the awkward situation where a nil is returned for the query and the user has to find out what is causing it. This pull request tries to quicken this debugging proces by at least indicating the point of failure by raising a descriptive error.

[1] pry(main)> require 'sparql/client'
=> true
[2] pry(main)> s = SPARQL::Client.new('http://localhost:8890/sparql')
=> #<SPARQL::Client:0x8fc(http://localhost:8890/sparql)>
[3] pry(main)> s.query("CONSTRUCT  {?s a ?type}  WHERE {?s a ?type}").first
NoMethodError: undefined method `first' for nil:NilClass
from (pry):3:in `<eval>'
[4] pry(main)> require 'rdf/turtle'
=> true
[5] pry(main)> s = SPARQL::Client.new('http://localhost:8890/sparql')
=> #<SPARQL::Client:0x902(http://localhost:8890/sparql)>
[6] pry(main)> s.query("CONSTRUCT  {?s a ?type}  WHERE {?s a ?type}").first
=> [#<RDF::URI:0x906 URI:http://www.openlinksw.com/virtrdf-data-formats#default-iid>, #<RDF::URI:0x908 URI:http://www.w3.org/1999/02/22-rdf-syntax-ns#type>, #<RDF::URI:0x90a URI:http://www.openlinksw.com/schemas/virtrdf#QuadMapFormat>]

This pull request replaces #66 and should be merged after #67.

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.008%) to 94.437% when pulling b5ea2df2c13ff98bffb82756de829594119e6372 on nvdk:no-suitable-rdf-reader into ddf951d03c8af2c9ce589a5667d041e5b137e529 on ruby-rdf:develop.

coveralls commented 8 years ago

Coverage Status

Coverage decreased (-0.1%) to 94.294% when pulling 46e3984bddca3499d65a2bd6f4b7f1ed10792d1c on nvdk:no-suitable-rdf-reader into ddf951d03c8af2c9ce589a5667d041e5b137e529 on ruby-rdf:develop.

gkellogg commented 8 years ago

Looks good, thanks for the contribution! If you haven't yet submitted an UNLICENSE declaration, please consider doing so.

nvdk commented 8 years ago

I dedicate any and all copyright interest in this software to the public domain. I make this dedication for the benefit of the public at large and to the detriment of my heirs and successors. I intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

if that fails in your jurisdiction, you can still use my contribution under a MIT license :speak_no_evil: