From 80f659858cba0b1faa46dfc5055c0dd0ba556613 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 7 Jun 2016 21:34:04 -0400 Subject: [PATCH] Fail with excplicit message when unable to load results file Previously, we would simply show an empty results window. Not very helpful. --- core/app.py | 10 +++++++++- core/results.py | 5 +---- core/tests/results_test.py | 8 ++++---- hscommon | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/app.py b/core/app.py index 9345c64e..e20d6c30 100644 --- a/core/app.py +++ b/core/app.py @@ -148,7 +148,7 @@ class DupeGuru(Broadcaster): self.stats_label = StatsLabel(self) self.result_table = None self.deletion_options = DeletionOptions() - self.progress_window = ProgressWindow(self._job_completed) + self.progress_window = ProgressWindow(self._job_completed, self._job_error) children = [self.directory_tree, self.stats_label, self.details_panel] for child in children: child.connect() @@ -307,6 +307,14 @@ class DupeGuru(Broadcaster): }[jobid] self.view.show_message(msg) + def _job_error(self, jobid, err): + if jobid == JobType.Load: + msg = tr("Could not load file: {}").format(err) + self.view.show_message(msg) + return False + else: + raise err + @staticmethod def _remove_hardlink_dupes(files): seen_inodes = set() diff --git a/core/results.py b/core/results.py index d4de7203..159805a3 100644 --- a/core/results.py +++ b/core/results.py @@ -222,10 +222,7 @@ class Results(Markable): do_match(other_files[0], other_files[1:], group) self.apply_filter(None) - try: - root = ET.parse(infile).getroot() - except Exception: - return + root = ET.parse(infile).getroot() group_elems = list(root.getiterator('group')) groups = [] marked = set() diff --git a/core/tests/results_test.py b/core/tests/results_test.py index 9d885959..7c147058 100644 --- a/core/tests/results_test.py +++ b/core/tests/results_test.py @@ -9,6 +9,7 @@ import os.path as op from xml.etree import ElementTree as ET +from pytest import raises from hscommon.testutil import eq_ from hscommon.util import first @@ -614,16 +615,15 @@ class TestCaseResultsXML: f.seek(0) app = DupeGuru() r = Results(app) - r.load_from_xml(f, None) + with raises(ET.ParseError): + r.load_from_xml(f, None) eq_(0, len(r.groups)) def test_load_non_existant_xml(self): app = DupeGuru() r = Results(app) - try: + with raises(IOError): r.load_from_xml('does_not_exist.xml', None) - except IOError: - self.fail() eq_(0, len(r.groups)) def test_remember_match_percentage(self): diff --git a/hscommon b/hscommon index 316af1bc..fd90d2e6 160000 --- a/hscommon +++ b/hscommon @@ -1 +1 @@ -Subproject commit 316af1bca53915f99b9bb874064cba6bee881cc1 +Subproject commit fd90d2e601752b9bf9cdd32bb6b7613fa05ec097