Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print nice errors to the screen #362

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SolrPhpClient/Apache/Solr/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,13 @@ protected function _sendRawGet($url, $timeout = FALSE)
// use the default timeout pulled from default_socket_timeout otherwise
stream_context_set_option($this->_getContext, 'http', 'timeout', $this->_defaultTimeout);
}

// Islandora: dump solr query address in debug mode
if (variable_get('islandora_solr_debug_mode', 0) && user_access('view islandora solr debug')) {
drupal_set_message(l('solr query',$url."&indent=on&debugQuery=true"));
}
//$http_response_header is set by file_get_contents
$response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_getContext), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);
$response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_getContext), @$http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wuhu! so you are editing the Client =) This opens a lot of possibilities ++

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't going to, but then I saw that islandora_solr_debug_mode block above. Also I have given up replacing this client, easier to fix it in Islandora 8.


if ($response->getHttpStatus() != 200)
{
Expand Down
10 changes: 2 additions & 8 deletions includes/breadcrumbs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,8 @@ function islandora_solr_get_breadcrumb_parent($pid) {
$solr_build->solrParams = islandora_solr_remove_base_filters($solr_build->solrParams);
$solr_build->solrParams = islandora_solr_clean_compound_filters($solr_build->solrParams);

try {
$solr_build->executeQuery(FALSE);
$results = (array) $solr_build->islandoraSolrResult['response']['objects'];
}
catch (Exception $e) {
$results = array();
drupal_set_message(check_plain(t('Error searching Solr index')) . ' ' . $e->getMessage(), 'error', FALSE);
}
$solr_build->executeQuery(FALSE);
$results = (array) $solr_build->islandoraSolrResult['response']['objects'];

$find_solr_value = function($o, $field) {
if (isset($o[$field])) {
Expand Down
13 changes: 4 additions & 9 deletions includes/compound_backend.inc
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,10 @@ function islandora_solr_compound_object_query($pid) {
$start += 1;
$solr_build->solrStart = $start * $rows;
$solr_build->solrLimit = $rows;
try {
$solr_build->executeQuery(FALSE);
$results = (array) $solr_build->islandoraSolrResult['response']['objects'];
$constituents = array_merge($constituents, $results);
}
catch (Exception $e) {
drupal_set_message(check_plain(t('Error searching Solr index')) . ' ' . $e->getMessage(), 'error', FALSE);
break;
}
$solr_build->executeQuery(FALSE);
$results = (array) $solr_build->islandoraSolrResult['response']['objects'];
$constituents = array_merge($constituents, $results);

if (is_null($total) && isset($solr_build->islandoraSolrResult['response']['numFound'])) {
$total = $solr_build->islandoraSolrResult['response']['numFound'];
}
Expand Down
2 changes: 1 addition & 1 deletion includes/query_processor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class IslandoraSolrQueryProcessor {
$results = $solr->search($solr_query, $this->solrStart, $this->solrLimit, $this->solrParams, $method);
}
catch (Exception $e) {
drupal_set_message(check_plain(t('Error searching Solr index')) . ' ' . $e->getMessage(), 'error');
islandora_solr_technical_difficulties($e);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this name.. we need a hook named the same way (kidding)

}

$object_results = array();
Expand Down
23 changes: 23 additions & 0 deletions islandora_solr.module
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,26 @@ function islandora_solr_preprocess_islandora_objects_subset(&$variables) {
$variables['limit'] = $_islandora_solr_queryclass->solrLimit;
}
}

/**
* Make nice text for screen and log the exception to watchdog.
*
* @param \Exception $e
* The exception.
*/
function islandora_solr_technical_difficulties(Exception $e) {
// Only report the error once per screen.
$islandora_solr_error_reported = &drupal_static(__FUNCTION__, false);

if ($islandora_solr_error_reported !== true) {
$message = "We are experiencing technical difficulties at this time and are working to fix the problem. Please try back later.";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final request. Could we have a way of customizing this message? Since it's front facing.. i know i know we did not have it before so why now? Because people i know will ask for it for sure.. maybe a hook-ie? i mean, its not a blocker... since you can always disable reporting at all...but could be cool? sorry

drupal_set_message(t($message), 'warning');
watchdog("manidora", "Received exception @code: @message\nLine: @line in file: @file", array(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manidora?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOH!

'@code' => $e->getCode(),
'@message' => $e->getMessage(),
'@file' => $e->getFile(),
'@line' => $e->getLine(),
), WATCHDOG_ERROR);
$islandora_solr_error_reported = TRUE;
}
}