I have been using this and when it works it works well, but if there is an error the function returns NULL and there is no log of what went wrong.

I think that if there is an error while performnig the query it should be logged.

I have created a patch to log such errors to watchdog.
http://github.com/jeremyfrench/rdf/commit/34f18548a658e967869f8887465d92...

CommentFileSizeAuthor
#6 847142-06-sparql-log-errors.patch515 byteslinclark

Comments

Anonymous’s picture

I agree, I was just thinking this yesterday as I was working on SPARQL Views.

It might be good not just to log the error but also alert the site visitor with a message to the screen... anyone else have an opinion on that?

JeremyFrench’s picture

I wasn't sure about an error on the screen. I did initially, but as this is an API thing, it may be worth letting the calling function do that or optionally handle the fact there are no results gracefully.

The sparql module had an $errors parameter passed by reference which reported errors back to the calling function, are there any votes to do that here?

milesw’s picture

Project: Resource Description Framework (RDF) » RDF Extensions
scor’s picture

Project: RDF Extensions » SPARQL

If trigger_error('insert ARC2 error here', E_USER_ERROR); is used, errors will be reported to the screen depending on what the site "logging and error" settings is at admin/config/development/logging.

Anonymous’s picture

Ok, this sounds like a pretty easy fix. I'll give it a shot tonight.

Anonymous’s picture

StatusFileSize
new515 bytes

This was a simple patch.

Would someone mind testing this? For an easy test, you can do something like the following:

function sparql_request($query, $endpoint) {
  $endpoint->endpoint = 'foo'; 
  $rows = _sparql_request($query, $endpoint);
  return $rows;
}

As soon as it is RTBC I'll commit.

Anonymous’s picture

Status: Active » Needs review

Whoops, forgot needs review

stuartraetaylor’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. I've applied the patch and Drupal now displays errors from ARC as expected.

Anonymous’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for reviewing!

Fixed with commit http://drupalcode.org/project/sparql.git/commit/4b8d6e0

scor’s picture

+++ b/sparql.module
@@ -86,12 +86,17 @@ function _sparql_request($query, $endpoint) {
+  if ($errors = $store->getErrors()) {
+    // Log errors.
+    foreach ($errors as $error) {
+      trigger_error($error, E_USER_ERROR);
+    }
+    return NULL;

why not returning the results even if there are errors?

Anonymous’s picture

Only because they weren't returned in the original code... but I don't see a problem with changing that if you think we should.

JeremyFrench’s picture

Rationale behind returning null is that if there has been an error in the sparql request there will either be no results or they will be invalid.

Things have moved on a lot since then so I'm not sure if that is still true.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.