rsinger / worldcat-linkeddata-php

A PHP linked data client for WorldCat.org
MIT License
4 stars 1 forks source link

Undefined offset: 4 in Resource.php:96 #7

Open cboulanger opened 6 years ago

cboulanger commented 6 years ago

Thank you for this library, very useful!

Hi, when searching for book data via ISBN, I am getting the following error:

Undefined offset: 4 in /path/to/vendor/rsinger/worldcat-linkeddata-php/src/Resource.php:96

I am investigating why this could happen, but maybe you have an idea.

cboulanger commented 6 years ago

For the moment, I use a workaround

https://github.com/rsinger/worldcat-linkeddata-php/blob/master/src/Resource.php#L96

                    if( isset($ids[$index]) )
                      $results[$ids[$index]] = ['state' => 'fulfilled', 'value' => $response];
                    else
                      \Yii::warning("Undefined ids[$index] ");

But of course, the cause of the problem should be fixed...

rsinger commented 6 years ago

Hmm, thanks for passing this along. I think I've tracked it down to https://github.com/rsinger/worldcat-linkeddata-php/blob/master/src/Work.php#L120

Since array_diff() would be maintaining the keys, it needs to be wrapped in an array_values() somewhere, I think.

rsinger commented 6 years ago

(The question is where that's the most appropriate)

cboulanger commented 6 years ago

My fix doesn't do it:

yii\base\ErrorException: Undefined index:  in /..../vendor/rsinger/worldcat-linkeddata-php/src/Graph.php:41`
yii\base\ErrorException: array_diff(): Argument #1 is not an array in /.../vendor/rsinger/worldcat-linkeddata-php/src/Work.php:120
rsinger commented 6 years ago

@cboulanger Can you try #8 and see if that solves your issues?

If that is actually the problem, I'll figure out how to write a test for this.

cboulanger commented 6 years ago

Here is some log information on the errors that still occur.

https://gist.github.com/cboulanger/5f0214a13fde237a982c04dbf0880141#file-error-log

I have also added the list of ISBN that I have tested it with.

rsinger commented 6 years ago

@cboulanger Can you pull that branch try again? Apparently the workExample property can be either a string or array.

Thanks for the error log, this is helpful to see it at scale!

cboulanger commented 6 years ago

Sure, I hope I can do it later tonight. There are some inconsistencies in the returned data when compared to the schema.org specs. For example, the properties familiyName and givenName of http://schema.org/Person are sometimes returned as arrays even though according to the spec, they should be just strings.

rsinger commented 6 years ago

No worries if you don't get to it right away. Feel free to send any inconsistencies my way: one of the problems with working with this is that it's almost completely undocumented and the scale is so absolutely enormous that it's nearly impossible to find the edge cases until it's used in anger.

cboulanger commented 6 years ago

Unfortunately, still quite a few errors... I have updated the logs here: https://gist.github.com/cboulanger/5f0214a13fde237a982c04dbf0880141#file-error-log

And here is a list of ISBNs that faild to resolve to valid Work IDs:

https://gist.github.com/cboulanger/7094c57ee6d4ff4c5ab721cb3a81cd27

Do you know anyone that we could pass this info to? Maybe they can find the structural reason for the problem.

rsinger commented 6 years ago

Uggghhh. Sorry about that. I fixed the issue but still left the bad line in there. Try pulling and see if that helps. I get this:

>>> $manifestation = new \WorldCatLD\Manifestation();
=> WorldCatLD\Manifestation {#191}
>>> $manifestation->findByIsbn('0-415-30903-4');
=> null
>>> $w = $manifestation->getWork();
=> WorldCatLD\Work {#189}
>>> $w->getWorkExample()
=> [
     "http://www.worldcat.org/oclc/52144540" => WorldCatLD\Manifestation {#191},
   ]
rsinger commented 6 years ago

Regarding the data itself, see: https://www.oclc.org/developer/develop/linked-data/worldcat-entities.en.html

It looks like there's an email address for feedback.

cboulanger commented 6 years ago

We're almost there: Only Graph.php:41 and Work.php:100 still throw...

2018-05-19 10:53:54 [error][webservices] Error trying to import ISBN 978-0-226-14425-2:
2018-05-19 10:53:54 [error][webservices] yii\base\ErrorException: Undefined index:  in /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php:41
Stack trace:
#0 /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php(41): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/Users/cboulang...', 41, Array)
#1 /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php(118): WorldCatLD\Manifestation->getSubjectData()
#2 /server/modules/webservices/connectors/Worldcat.php(146): WorldCatLD\Manifestation->__get('datePublished')
[...]
2018-05-19 11:03:53 [error][webservices] Error trying to import ISBN 978-3-515-09007-0:
2018-05-19 11:03:53 [error][webservices] yii\base\ErrorException: Undefined index:  in /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php:41
Stack trace:
#0 /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php(41): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/Users/cboulang...', 41, Array)
#1 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(118): WorldCatLD\Work->getSubjectData()
#2 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(80): WorldCatLD\Work->getUnresolvedWorkExamples()
#3 /server/modules/webservices/connectors/Worldcat.php(78): WorldCatLD\Work->getWorkExample()
[...]
2018-05-19 11:44:03 [error][webservices] Error trying to import ISBN 978-3-531-17503-4:
2018-05-19 11:44:03 [error][webservices] yii\base\ErrorException: Undefined index:  in /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php:41
Stack trace:
#0 /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php(41): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/Users/cboulang...', 41, Array)
#1 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(118): WorldCatLD\Work->getSubjectData()
#2 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(80): WorldCatLD\Work->getUnresolvedWorkExamples()
#3 /server/modules/webservices/connectors/Worldcat.php(78): WorldCatLD\Work->getWorkExample()
[...]
2018-05-19 11:44:22 [error][webservices] Error trying to import ISBN 978-3-531-19832-3:
2018-05-19 11:44:22 [error][webservices] yii\base\ErrorException: Undefined index:  in /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php:41
Stack trace:
#0 /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php(41): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/Users/cboulang...', 41, Array)
#1 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(118): WorldCatLD\Work->getSubjectData()
#2 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(80): WorldCatLD\Work->getUnresolvedWorkExamples()
#3 /server/modules/webservices/connectors/Worldcat.php(78): WorldCatLD\Work->getWorkExample()
[...]
2018-05-19 11:48:33 [error][webservices] Error trying to import ISBN 978-3-663-02848-2:
2018-05-19 11:48:33 [error][webservices] yii\base\ErrorException: Undefined index:  in /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php:41
Stack trace:
#0 /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php(41): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/Users/cboulang...', 41, Array)
#1 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(118): WorldCatLD\Work->getSubjectData()
#2 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(80): WorldCatLD\Work->getUnresolvedWorkExamples()
#3 /server/modules/webservices/connectors/Worldcat.php(78): WorldCatLD\Work->getWorkExample()
#4 /server/modules/webservices/connectors/Worldcat.php(123): app\modules\webservices\connectors\Worldcat->createManifestations(Object(lib\cql\SearchClause))
[...]
2018-05-19 11:50:04 [error][webservices] Error trying to import ISBN 978-3-8252-2721-0:
2018-05-19 11:50:04 [error][webservices] yii\base\ErrorException: Undefined index:  in /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php:41
Stack trace:
#0 /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php(41): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/Users/cboulang...', 41, Array)
#1 /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php(118): WorldCatLD\Manifestation->getSubjectData()
#2 /server/modules/webservices/connectors/Worldcat.php(146): WorldCatLD\Manifestation->__get('datePublished')
[...]
2018-05-19 11:51:45 [error][webservices] Error trying to import ISBN 978-3-8452-6356-4:
2018-05-19 11:51:45 [error][webservices] yii\base\ErrorException: array_search() expects parameter 2 to be array, string given in /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php:100
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'array_search() ...', '/Users/cboulang...', 100, Array)
#1 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(100): array_search('http://www.worl...', 'http://www.worl...')
#2 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(80): WorldCatLD\Work->hydrateExamples(Array)
#3 /server/modules/webservices/connectors/Worldcat.php(78): WorldCatLD\Work->getWorkExample()
[...]
2018-05-19 11:52:32 [error][webservices] Error trying to import ISBN 978-3-8487-2262-4:
2018-05-19 11:52:32 [error][webservices] yii\base\ErrorException: array_search() expects parameter 2 to be array, string given in /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php:100
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'array_search() ...', '/Users/cboulang...', 100, Array)
#1 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(100): array_search('http://www.worl...', 'http://www.worl...')
#2 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(80): WorldCatLD\Work->hydrateExamples(Array)
#3 /server/modules/webservices/connectors/Worldcat.php(78): WorldCatLD\Work->getWorkExample()
[...]
2018-05-19 11:53:09 [error][webservices] Error trying to import ISBN 978-3-89669-551-2:
2018-05-19 11:53:09 [error][webservices] yii\base\ErrorException: Undefined index:  in /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php:41
Stack trace:
#0 /server/vendor/rsinger/worldcat-linkeddata-php/src/Graph.php(41): yii\base\ErrorHandler->handleError(8, 'Undefined index...', '/Users/cboulang...', 41, Array)
#1 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(118): WorldCatLD\Work->getSubjectData()
#2 /server/vendor/rsinger/worldcat-linkeddata-php/src/Work.php(80): WorldCatLD\Work->getUnresolvedWorkExamples()
#3 /server/modules/webservices/connectors/Worldcat.php(78): WorldCatLD\Work->getWorkExample()
[...]
rsinger commented 6 years ago

Hmm. This looks like a different issue, because those examples work fine for me.

Looking at the timestamps, this seems to happen irregularly - based on the error my guess would be that the work graph wasn't actually returned when it was retrieved. Worldcat must have sent back a 200 response, but maybe an empty or malformed one. How many requests, roughly, had you done prior to the first log line?

One option here would be try to refetch the work graph if it's empty when we try to access it, but I'd like to put that in a separate ticket.

cboulanger commented 6 years ago

Unfortunately, I haven't kept the log. My test set is around 450 ISBNs so there have been quite a few requests before the errors occurred. I can do a new check but I'll wait if @librarywebchic can find out something about the invalid work ids before I run it again...

librarywebchic commented 6 years ago

Have you found any Work ID/URLs that work?

On Mon, May 21, 2018 at 2:04 PM, Christian Boulanger < notifications@github.com> wrote:

Unfortunately, I haven't kept the log. My test set is around 450 ISBNs so there have been quite a few requests before the errors occurred. I can do a new check but I'll wait if @librarywebchic https://github.com/librarywebchic can find out something about the invalid work ids before I run it again...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rsinger/worldcat-linkeddata-php/issues/7#issuecomment-390751037, or mute the thread https://github.com/notifications/unsubscribe-auth/AAa72a1B7MLkrbsvTfK1ers4Fi6Scqooks5t0w-zgaJpZM4T8za4 .

cboulanger commented 6 years ago

@librarywebchic Thanks for looking into this. Among the list of these ISBNs https://gist.github.com/cboulanger/5f0214a13fde237a982c04dbf0880141#file-test-isbn-list-txt these failed: https://gist.github.com/cboulanger/7094c57ee6d4ff4c5ab721cb3a81cd27 i.e. quite a few succeeded...

librarywebchic commented 6 years ago

It does help to know some are succeeding. It helps me try to narrow down why others are failing.

On Mon, May 21, 2018 at 2:50 PM, Christian Boulanger < notifications@github.com> wrote:

@librarywebchic https://github.com/librarywebchic Thanks for looking into this. Among the list of these ISBNs https://gist.github.com/cboulanger/5f0214a13fde237a982c04dbf08801 41#file-test-isbn-list-txt these failed: https://gist.github.com/cboulanger/7094c57ee6d4ff4c5ab721cb3a81cd27 i.e. quite a few succeeded...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rsinger/worldcat-linkeddata-php/issues/7#issuecomment-390762463, or mute the thread https://github.com/notifications/unsubscribe-auth/AAa72bSX7oJA5h_-lsKsYipIg0G_b6mcks5t0xp6gaJpZM4T8za4 .