Skip to content

Commit

Permalink
Handle bugzilla jsonrpc errors
Browse files Browse the repository at this point in the history
Bugs not found are non-fatal and should be shown in the generated HTML,
but authentication errors should be fatal.
  • Loading branch information
perlpunk committed Nov 11, 2021
1 parent 4b6237a commit 433e965
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion openqa_review/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ class CacheNotFoundError(DownloadError):
pass


class BugzillaError(Exception):
"""Bugzilla API returned error."""

def __init__(self, url, code, msg):
"""Initialize."""
self.url = url
self.code = code
self.message = msg

def __str__(self):
"""Stringify."""
return "Error retrieving '%s': code=%s msg='%s'" % (self.url, self.code, self.message)


class BugNotFoundError(BugzillaError):
"""A bugref points to a non-existing bug URL."""

pass


def url_to_filename(url):
"""
Convert URL to a valid, unambigous filename.
Expand Down Expand Up @@ -170,7 +190,14 @@ def json_rpc_get(self, url, method, params, cache=True):
absolute_url = url if not url.startswith("/") else urljoin("http://dummy/", str(url))
get_params = SortedDict({"method": method, "params": json.dumps([params])})
get_url = requests.Request("GET", absolute_url, params=get_params).prepare().url
return self.get_json(get_url.replace("http://dummy", ""), cache)
response = self.get_json(get_url.replace("http://dummy", ""), cache)
if "error" in response and response["error"] is not None:
error = response["error"]
if error["code"] == 101:
raise BugNotFoundError(get_url, error["code"], error["message"])
else:
raise BugzillaError(get_url, error["code"], error["message"])
return response

def json_rpc_post(self, url, method, params):
"""Execute JSON RPC POST request.
Expand Down
4 changes: 2 additions & 2 deletions openqa_review/openqa_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from openqa_review.browser import Browser, DownloadError, add_load_save_args # isort:skip
from openqa_review.browser import Browser, DownloadError, BugNotFoundError, add_load_save_args # isort:skip


# treat humanfriendly as optional dependency
Expand Down Expand Up @@ -701,7 +701,7 @@ def __init__(self, bugref, bugref_href, query_issue_status=False, progress_brows
)
self.msg = str(e)
self.error = True
except TypeError as e:
except BugNotFoundError as e:
log.error(
"Error retrieving details for bugref %s (%s): %s\n%s"
% (self.bugref, self.bugref_href, e, traceback.format_exc())
Expand Down

0 comments on commit 433e965

Please sign in to comment.