From a0c983e0b8dccf2dbcdf63fef35c073d45cf017f Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 14 Jun 2018 13:23:50 -0400 Subject: [PATCH] protect against errors from the hound API When codesearch.o.o is re-indexing the API responds with something that is not JSON. Rather than worry about all of the various errors we could receive from an API that is only providing advisory information, catch anything, log it, and proceed in a safe manner. Change-Id: Ia910215029b3ece31db180396dbb50c82a7f3a59 Signed-off-by: Doug Hellmann --- openstack_releases/hound.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/openstack_releases/hound.py b/openstack_releases/hound.py index 82f4ca1344..37eb7bcfbe 100644 --- a/openstack_releases/hound.py +++ b/openstack_releases/hound.py @@ -16,9 +16,12 @@ """ +import logging + import requests +LOG = logging.getLogger(__name__) _URL = 'http://codesearch.openstack.org/api/v1/search' @@ -39,14 +42,19 @@ def _query(q, **kwds): def get_dependency_listings(package_name): - return _query( - q=package_name, - # NOTE(dhellmann): Including setup.cfg shows *lots* of results - # for oslo.config because of the plugins for the config - # generator. It would be nice to figure out how to filter - # those. - files='(.*requirements.txt|.*constraint.*.txt)', - ) + try: + return _query( + q=package_name, + # NOTE(dhellmann): Including setup.cfg shows *lots* of results + # for oslo.config because of the plugins for the config + # generator. It would be nice to figure out how to filter + # those. + files='(.*requirements.txt|.*constraint.*.txt)', + ) + except Exception as e: + LOG.error('Could not fetch users of %s: %s', + package_name, e) + return {} def show_dependency_listings(package_name, official_repos):