Merge ~pappacena/launchpad:better-error-msg-snap-without-source into launchpad:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: c2b291f65b2c0abc7111a8b3bb0122d56d13f5d4
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/launchpad:better-error-msg-snap-without-source
Merge into: launchpad:master
Diff against target: 45 lines (+13/-2)
2 files modified
lib/lp/snappy/model/snap.py (+3/-1)
lib/lp/snappy/tests/test_snap.py (+10/-1)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+398726@code.launchpad.net

Commit message

LP: #1916912 Improving error message when trying to build snap without source

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Thiago F. Pappacena (pappacena) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/snappy/model/snap.py b/lib/lp/snappy/model/snap.py
2index 7e3d14c..860ac98 100644
3--- a/lib/lp/snappy/model/snap.py
4+++ b/lib/lp/snappy/model/snap.py
5@@ -1,4 +1,4 @@
6-# Copyright 2015-2020 Canonical Ltd. This software is licensed under the
7+# Copyright 2015-2021 Canonical Ltd. This software is licensed under the
8 # GNU Affero General Public License version 3 (see the file LICENSE).
9
10 from __future__ import absolute_import, print_function, unicode_literals
11@@ -1359,6 +1359,8 @@ class SnapSet:
12 """See `ISnapSet`."""
13 if ISnap.providedBy(context):
14 context = context.source
15+ if context is None:
16+ raise CannotFetchSnapcraftYaml("Snap source is not defined")
17 try:
18 paths = (
19 "snap/snapcraft.yaml",
20diff --git a/lib/lp/snappy/tests/test_snap.py b/lib/lp/snappy/tests/test_snap.py
21index 706255a..cfb995c 100644
22--- a/lib/lp/snappy/tests/test_snap.py
23+++ b/lib/lp/snappy/tests/test_snap.py
24@@ -1,4 +1,4 @@
25-# Copyright 2015-2020 Canonical Ltd. This software is licensed under the
26+# Copyright 2015-2021 Canonical Ltd. This software is licensed under the
27 # GNU Affero General Public License version 3 (see the file LICENSE).
28
29 """Test snap packages."""
30@@ -1731,6 +1731,15 @@ class TestSnapSet(TestCaseWithFactory):
31 store_names[0], owner=owners[1],
32 visible_by_user=owners[0]))
33
34+ def test_getSnapcraftYaml_snap_no_source(self):
35+ [git_ref] = self.factory.makeGitRefs()
36+ snap = self.factory.makeSnap(git_ref=git_ref)
37+ with admin_logged_in():
38+ git_ref.repository.destroySelf(break_references=True)
39+ self.assertRaisesWithContent(
40+ CannotFetchSnapcraftYaml, "Snap source is not defined",
41+ getUtility(ISnapSet).getSnapcraftYaml, snap)
42+
43 def test_getSnapcraftYaml_bzr_snap_snapcraft_yaml(self):
44 def getInventory(unique_name, dirname, *args, **kwargs):
45 if dirname == "snap":