Merge ~pappacena/launchpad:upload-parse-error-msg into launchpad:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: d069efd76279294259f177923c9e54d03921b117
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/launchpad:upload-parse-error-msg
Merge into: launchpad:master
Diff against target: 58 lines (+24/-4)
2 files modified
lib/lp/archiveuploader/nascentuploadfile.py (+3/-3)
lib/lp/archiveuploader/tests/test_nascentuploadfile.py (+21/-1)
Reviewer Review Type Date Requested Status
Ioana Lasc Approve
Review via email: mp+386290@code.launchpad.net

Commit message

Adding more information to DebFile parsing when uploading deb package

To post a comment you must log in.
d069efd... by Thiago F. Pappacena

Removing warning

Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/archiveuploader/nascentuploadfile.py b/lib/lp/archiveuploader/nascentuploadfile.py
2index d69f25d..52b8b58 100644
3--- a/lib/lp/archiveuploader/nascentuploadfile.py
4+++ b/lib/lp/archiveuploader/nascentuploadfile.py
5@@ -563,10 +563,10 @@ class BaseBinaryUploadFile(PackageUploadFile):
6 deb_file = apt_inst.DebFile(self.filepath)
7 control_file = deb_file.control.extractdata("control")
8 control_lines = apt_pkg.TagSection(control_file, bytes=True)
9- except Exception:
10+ except Exception as e:
11 yield UploadError(
12- "%s: extracting control file raised %s, giving up."
13- % (self.filename, sys.exc_type))
14+ "%s: extracting control file raised %s: %s. giving up."
15+ % (self.filename, sys.exc_type, e))
16 return
17
18 for mandatory_field in self.mandatory_fields:
19diff --git a/lib/lp/archiveuploader/tests/test_nascentuploadfile.py b/lib/lp/archiveuploader/tests/test_nascentuploadfile.py
20index ff63636..1ad7a81 100644
21--- a/lib/lp/archiveuploader/tests/test_nascentuploadfile.py
22+++ b/lib/lp/archiveuploader/tests/test_nascentuploadfile.py
23@@ -41,7 +41,10 @@ from lp.archiveuploader.nascentuploadfile import (
24 from lp.archiveuploader.tests import AbsolutelyAnythingGoesUploadPolicy
25 from lp.buildmaster.enums import BuildStatus
26 from lp.registry.interfaces.pocket import PackagePublishingPocket
27-from lp.services.compat import lzma
28+from lp.services.compat import (
29+ lzma,
30+ mock,
31+ )
32 from lp.services.log.logger import BufferLogger
33 from lp.services.osutils import write_file
34 from lp.soyuz.enums import (
35@@ -517,6 +520,23 @@ class DebBinaryUploadFileTests(PackageUploadFileTestCase):
36 uploadfile.extractAndParseControl()
37 self.assertEqual([], list(uploadfile.verifyFormat()))
38
39+ @mock.patch("lp.archiveuploader.nascentuploadfile.apt_inst")
40+ def test_extractAndParseControl_UploadError_message(self, m_apt_inst):
41+ # extractAndParseControl should yield a reasonable error message if
42+ # apt_inst.DebFile raises an exception
43+ m_apt_inst.DebFile.side_effect = KeyError("banana not found")
44+ uploadfile = self.createDebBinaryUploadFile(
45+ "empty_0.1_all.deb", "main/admin", "extra", "empty", "0.1", None,
46+ members=[])
47+ errors = list(uploadfile.extractAndParseControl())
48+ self.assertEqual(1, len(errors))
49+ error = errors[0]
50+ self.assertIsInstance(error, UploadError)
51+ self.assertEqual(
52+ "empty_0.1_all.deb: extracting control file raised "
53+ "<type 'exceptions.KeyError'>: u'banana not found'."
54+ " giving up.", str(error))
55+
56 def test_verifyDebTimestamp_SystemError(self):
57 # verifyDebTimestamp produces a reasonable error if we provoke a
58 # SystemError from apt_inst.DebFile.