apachesolr_get_solr() throws exceptions when the default environment stored in the apachesolr_default_environment is not a valid environment; this can happen if the default environment is deleted programmatically or if the variable is unset and is allowed to default to 'solr' when the default 'solr' environment has been deleted.
A site is probably doing something wrong if this variable is not present and set to a valid environment, but it can potentially happen with Features and exportable environments. I get the impression that this function is supposed to throw an exception, and that callers are expected to wrap it in a try-catch, but there are several functions that do not do this. Should all uses of apachesolr_get_solr() be wrapped in try-catch blocks? If so, I'd be happy to write a patch...
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 1409878-9.patch | 7.44 KB | nick_vh |
| #1 | 1409878-1-apachesolr-uncaught_exceptions_with_no_default_environment.patch | 6.11 KB | becw |
Comments
Comment #1
becw commentedHere's a patch that wraps the remaining calls to
apachesolr_get_solr()in try-catch blocks, and throws an exception when there is no default environment configured.Comment #2
nick_vhI can see the use of this. Are you sure these are all the apachesolr_get_solr calls?
Would it be easier if we make this try catch in apachesolr_get_solr itself?
Comment #3
becw commentedDoing the try-catch in
apachesolr_get_solr()would mean that it only needs to happen in one place, but all of the calls to that function rely on getting aDrupalApacheSolrServiceobject back. If we changedapachesolr_get_solr(), everything that currently uses it would have to be updated to handle getting FALSE instead of an object... so I don't think it would necessarily be easier.Comment #4
pwolanin commentedlooks reasonable, espeically if the function is already documented to throw an exception
Comment #5
nick_vhCommitted! Gave you credit for the patch ;-)
Thanks
Comment #6
nick_vhComment #7
becw commentedAwesome, thanks!
Comment #8
pwolanin commentedComment #9
nick_vhCommited to 6.x-3.x
Comment #10
nick_vhComment #11
nick_vh