Blob Blame History Raw
From 756addbc8e36fd7ce654ac4f0ea38ee34ae794e2 Mon Sep 17 00:00:00 2001
From: Ernestas Kulik <ekulik@redhat.com>
Date: Mon, 18 May 2020 08:09:54 +0200
Subject: [PATCH] problems: Handle errors when fetching titles

Fallout from 837cb787caa4667a928673353e4ea8205ef9419a.

If any of the URIs in reported_to are inaccessible, the resulting HTTP
error will become an exception, which is totally unnecessary, because
the user will most likely have no idea what to do. Handling the
exception gracefully will just keep the dummy title.

This commit also narrows down the handled exceptions to GLib.Error,
since BeautifulSoup will eat whatever we feed it and not complain and
any other error should probably get some attention.

https://bugzilla.redhat.com/show_bug.cgi?id=1836614
---
 src/gnome_abrt/problems.py | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/gnome_abrt/problems.py b/src/gnome_abrt/problems.py
index 4e50b79..2854aa8 100644
--- a/src/gnome_abrt/problems.py
+++ b/src/gnome_abrt/problems.py
@@ -18,7 +18,8 @@
 import datetime
 import logging
 import re
-from urllib import request
+import sys
+import urllib
 
 from bs4 import BeautifulSoup
 
@@ -114,22 +115,25 @@ class Problem:
                 self._url_done = True
 
                 def on_update_title(source_object, res, user_data):
-                    _, title = res.propagate_value()
-                    if title:
-                        self._title = title
-                        self._problem.source.notify(ProblemSource.CHANGED_PROBLEM,
-                                                    self._problem)
+                    try:
+                        _, title = res.propagate_value()
+                        if title:
+                            self._title = title
+                            self._problem.source.notify(ProblemSource.CHANGED_PROBLEM,
+                                                        self._problem)
+                    except GLib.Error as error:
+                        print(error.message, file=sys.stderr)
 
                 task = Gio.Task.new(None, None, on_update_title, None)
 
                 def update_title(task, source_object, task_data, cancellable):
                     try:
-                        html = request.urlopen(self._data).read().decode("UTF-8")
+                        html = urllib.request.urlopen(self._data).read().decode("UTF-8")
                         soup = BeautifulSoup(html, "html.parser")
                         value = GObject.Value(str, soup.title.string)
 
                         task.return_value(value)
-                    except Exception as ex:
+                    except urllib.error.HTTPError as ex:
                         error = GLib.Error("Fetching title for problem report failed: %s" % (ex))
                         task.return_error(error)
 
-- 
2.26.2