Skip to content

Commit

Permalink
Wrap excerpt in try/except
Browse files Browse the repository at this point in the history
excerpt can kick up socket.error and socket.timeout.  So we wrap it and
throw ExcerptErrors if things go awry.
  • Loading branch information
willkg committed Nov 9, 2011
1 parent b3e795b commit ad953dc
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions oedipus/__init__.py
Expand Up @@ -310,9 +310,11 @@ def excerpt(self, result):
"""Take a result and return the excerpt as a list of
unicodes--one for each highlight_field in the order specified.
:raises ExcerptError: Raises an ``ExcerptError`` if ``excerpt``
was called before results were calculated or if
``highlight_fields`` is not a subset of ``fields``.
:raises ExcerptError: Raises an ``ExcerptError`` if
``excerpt`` was called before results were calculated, if
``highlight_fields`` is not a subset of ``fields``, or if
there was a socket.error or socket.timeout trying to
retrieve the excerpt.
"""
# This catches the case where results haven't been calculated.
Expand Down Expand Up @@ -348,8 +350,16 @@ def excerpt(self, result):
options[mem] = getattr(self.meta, 'excerpt_' + mem)

sphinx = self._sphinx()
excerpt = sphinx.BuildExcerpts(
list(docs), self.meta.index, self._query, options)

try:
excerpt = sphinx.BuildExcerpts(
list(docs), self.meta.index, self._query, options)
except socket.error, msg:
# The sphinxapi exceptions suck, so raising our own and
# ignoring theirs doesn't make a big difference.
raise ExcerptError('Socket error building excerpt: %s!', msg)
except socket.timeout:
raise ExcerptError('Socket timeout error with excerpt!')

# TODO: This assumes the data is in utf-8 which it might not
# be depending on the backing database configuration.
Expand Down

0 comments on commit ad953dc

Please sign in to comment.