Merge lp:~wgrant/loggerhead/bug-728209 into lp:loggerhead

Proposed by William Grant
Status: Merged
Merged at revision: 467
Proposed branch: lp:~wgrant/loggerhead/bug-728209
Merge into: lp:loggerhead
Diff against target: 74 lines (+26/-3)
3 files modified
NEWS (+3/-0)
loggerhead/controllers/view_ui.py (+12/-2)
loggerhead/tests/test_controllers.py (+11/-1)
To merge this branch: bzr merge lp:~wgrant/loggerhead/bug-728209
Reviewer Review Type Date Requested Status
Loggerhead Reviewers Pending
Review via email: mp+91383@code.launchpad.net

Commit message

Stop crashing when viewing a non-existent filename or fileid.

Description of the change

Stop crashing when viewing a non-existent filename or fileid.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2012-02-02 07:42:24 +0000
3+++ NEWS 2012-02-03 01:32:22 +0000
4@@ -55,6 +55,9 @@
5 - Make tz calculations consistent and use UTC in the UI everywhere we show
6 a precise timestamp. (Robert Collins, #594591)
7
8+ - Avoid crashing when viewing or annotating a non-existent file.
9+ (William Grant, #728209)
10+
11
12 1.18.1 [24Mar2011]
13 ------------------
14
15=== modified file 'loggerhead/controllers/view_ui.py'
16--- loggerhead/controllers/view_ui.py 2011-09-08 00:33:28 +0000
17+++ loggerhead/controllers/view_ui.py 2012-02-03 01:32:22 +0000
18@@ -24,7 +24,12 @@
19 import bzrlib.textfile
20 import bzrlib.osutils
21
22-from paste.httpexceptions import HTTPBadRequest, HTTPServerError, HTTPMovedPermanently
23+from paste.httpexceptions import (
24+ HTTPBadRequest,
25+ HTTPMovedPermanently,
26+ HTTPNotFound,
27+ HTTPServerError,
28+ )
29
30 from loggerhead.controllers import TemplatedBranchView
31 try:
32@@ -119,7 +124,12 @@
33 raise HTTPServerError('Could not fetch changes')
34 branch_breadcrumbs = util.branch_breadcrumbs(path, inv, 'files')
35
36- if inv[file_id].kind == "directory":
37+ try:
38+ file = inv[file_id]
39+ except bzrlib.errors.NoSuchId:
40+ raise HTTPNotFound()
41+
42+ if file.kind == "directory":
43 raise HTTPMovedPermanently(self._branch.context_url(['/files', revno_url, path]))
44
45 return {
46
47=== modified file 'loggerhead/tests/test_controllers.py'
48--- loggerhead/tests/test_controllers.py 2011-11-25 01:41:07 +0000
49+++ loggerhead/tests/test_controllers.py 2012-02-03 01:32:22 +0000
50@@ -22,7 +22,10 @@
51 from paste.fixture import (
52 AppError,
53 )
54-from paste.httpexceptions import HTTPServerError
55+from paste.httpexceptions import (
56+ HTTPNotFound,
57+ HTTPServerError,
58+ )
59
60 from testtools.matchers import (
61 Matcher,
62@@ -202,6 +205,13 @@
63 annotated = annotate_info['annotated']
64 self.assertEqual(0, len(annotated))
65
66+ def test_annotate_nonexistent_file(self):
67+ history = [('rev1', '' , '.')]
68+ ann_ui = self.make_annotate_ui_for_file_history('file_id', history)
69+ ann_ui.args = ['rev1']
70+ self.assertRaises(
71+ HTTPNotFound, ann_ui.get_values, 'not-filename', {}, {})
72+
73
74 class TestFileDiffUI(BasicTests):
75

Subscribers

People subscribed via source and target branches