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 all commits
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
11 changes: 11 additions & 0 deletions includes/admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ function islandora_solr_admin_index_settings($form, &$form_state) {
'#default_value' => variable_get('islandora_solr_force_update_index_after_object_purge', 0),
);

$form['solr_ajax_wrapper']['islandora_solr_technical_difficulties_message'] = array(
'#type' => 'textfield',
'#title' => t('Solr unavailable message.'),
'#description' => t('When Solr throws an Exception this message is displayed to the users.'),
'#size' => 150,
'#weight' => 10,
'#default_value' => variable_get('islandora_solr_technical_difficulties_message', ISLANDORA_SOLR_DIFFICULTIES_MESSAGE),
);

// Actions.
$form['actions'] = array(
'#type' => 'actions',
Expand Down Expand Up @@ -200,13 +209,15 @@ function _islandora_solr_admin_index_settings_submit($form, &$form_state) {
variable_set('islandora_solr_url', $form_state['values']['islandora_solr_url']);
variable_set('islandora_solr_request_handler', $form_state['values']['islandora_solr_request_handler']);
variable_set('islandora_solr_force_update_index_after_object_purge', $form_state['values']['islandora_solr_force_update_index_after_object_purge']);
variable_set('islandora_solr_technical_difficulties_message', $form_state['values']['islandora_solr_technical_difficulties_message']);
drupal_set_message(t('The Solr configuration options have been saved.'));
break;

case 'edit-reset':
variable_del('islandora_solr_url');
variable_del('islandora_solr_request_handler');
variable_del('islandora_solr_force_update_index_after_object_purge');
variable_del('islandora_solr_technical_difficulties_message');
drupal_set_message(t('The configuration options have been reset to their default values.'));
break;
}
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
1 change: 1 addition & 0 deletions islandora_solr.install
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function islandora_solr_uninstall() {
'islandora_solr_simple_search_label_title',
'islandora_solr_compound_relationship_field',
'islandora_solr_compound_sequence_pattern',
'islandora_solr_technical_difficulties_message',
));
array_walk($variables, 'variable_del');
}
Expand Down
26 changes: 26 additions & 0 deletions islandora_solr.module
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const ISLANDORA_SOLR_FACET_BUCKET_CLASSES_HOOK_BASE = 'islandora_solr_facet_buck

const ISLANDORA_SOLR_BREADCRUMB_BACKEND = 'islandora_solr_breadcrumb_backend';

const ISLANDORA_SOLR_DIFFICULTIES_MESSAGE = "We are experiencing technical difficulties at this time and are working to fix the problem. Please try back later.";

// Includes functions for common db queries.
require_once dirname(__FILE__) . '/includes/db.inc';
// Includes functions for common tasks.
Expand Down Expand Up @@ -632,3 +634,27 @@ 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) {
drupal_set_message(t("@message", array(
'@message' => variable_get('islandora_solr_technical_difficulties_message', ISLANDORA_SOLR_DIFFICULTIES_MESSAGE)
)), 'warning');
watchdog("islandora_solr", "Received exception @code: @message\nLine: @line in file: @file", array(
'@code' => $e->getCode(),
'@message' => $e->getMessage(),
'@file' => $e->getFile(),
'@line' => $e->getLine(),
), WATCHDOG_ERROR);
$islandora_solr_error_reported = TRUE;
}
}