Skip to content

Commit f99fc6a

Browse files
committed
Expect missing copyright field and ValueError errors
Expecting the errors enables to give better feedback to users than just a 500 error
1 parent b6a5357 commit f99fc6a

File tree

7 files changed

+58
-16
lines changed

7 files changed

+58
-16
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{#
2-
Copyright (C) 2015 The Debsources developers <info@sources.debian.net>.
2+
Copyright (C) 2016 The Debsources developers <info@sources.debian.net>.
33
See the AUTHORS file at the top-level directory of this distribution and at
44
https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=AUTHORS;hb=HEAD
55
License: GNU Affero General Public License, version 3 or above.
66
#}
77
{% extends name+"/base.html" %}
88

9-
{% block title %}404{% endblock %}
9+
{% block title %}Error{% endblock %}
1010
{% block content %}
1111
<h2>{{ self.title() }}</h2>
1212
<p>The debian/copyright file has a file paragraph without the <b>required</b> copyright field. The files paragraph is:
@@ -15,7 +15,8 @@ <h2>{{ self.title() }}</h2>
1515
<li>{{ files }}</li>
1616
{% endfor %}
1717
</ul>
18+
<a href="{{ url_for('sources.source', path_to=(package +'/'+version+'/debian/copyright'))}}">View raw copyright file</a>
1819
</p>
19-
<a href="/">Go home</a>
20+
<a href="{{ url_for('.license', path_to=(package +'/'+version))}}">Go back to the license page</a>
2021

2122
{% endblock %}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{#
2+
Copyright (C) 2016 The Debsources developers <info@sources.debian.net>.
3+
See the AUTHORS file at the top-level directory of this distribution and at
4+
https://anonscm.debian.org/gitweb/?p=qa/debsources.git;a=blob;f=AUTHORS;hb=HEAD
5+
License: GNU Affero General Public License, version 3 or above.
6+
#}
7+
{% extends name+"/base.html" %}
8+
9+
{% block title %}Error{% endblock %}
10+
{% block content %}
11+
<h2>{{ self.title() }}</h2>
12+
<p>Parsing the debian/copyright file yields a Value error. Causes of ValueError can be:
13+
<ul>
14+
<li>continued line must begin with " "</li>
15+
<li>missing value in one of the required attributes (Files, Copyright, License)</li>
16+
</ul>
17+
18+
<p><a href="{{ url_for('sources.source', path_to=(package +'/'+version+'/debian/copyright'))}}">View raw copyright file</a></p>
19+
</p>
20+
{% endblock %}

debsources/app/copyright/views.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import debsources.statistics as statistics
2323
from debsources.excepts import (Http404ErrorSuggestions, FileOrFolderNotFound,
2424
InvalidPackageOrVersionError,
25-
Http404MissingCopyright, Http404Error)
25+
Http404MissingCopyright, Http404Error,
26+
CopyrightValueError)
2627
from ..views import GeneralView, ChecksumView, session, app
2728
from ..sourcecode import SourceCodeIterator
2829
from ..pagination import Pagination
@@ -74,13 +75,16 @@ def get_objects(self, path_to):
7475
code=sourcefile,
7576
dump='True',
7677
nlines=sourcefile.get_number_of_lines(),)
77-
return dict(package=package,
78-
version=version,
79-
dump='False',
80-
header=helper.get_copyright_header(c),
81-
files=helper.parse_copyright_paragraphs_for_html_render(
82-
c, "/src/" + package + "/" + version + "/"),
83-
licenses=helper.parse_licenses_for_html_render(c))
78+
try:
79+
return dict(package=package,
80+
version=version,
81+
dump='False',
82+
header=helper.get_copyright_header(c),
83+
files=helper.parse_copyright_paragraphs_html_render(
84+
c, "/src/" + package + "/" + version + "/"),
85+
licenses=helper.parse_licenses_for_html_render(c))
86+
except ValueError as e:
87+
raise CopyrightValueError(package, version, e.message)
8488

8589

8690
class ChecksumLicenseView(ChecksumView):

debsources/app/patches/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from ..views import GeneralView, session
2020
from debsources.navigation import Location, SourceFile
2121
from debsources.excepts import (Http404ErrorSuggestions, FileOrFolderNotFound,
22-
InvalidPackageOrVersionError)
22+
InvalidPackageOrVersionError, Http404Error)
2323
from ..sourcecode import SourceCodeIterator
2424
from . import patches_helper as helper
2525

@@ -172,6 +172,8 @@ class PatchView(GeneralView):
172172

173173
def get_objects(self, path_to):
174174
path_dict = path_to.split('/')
175+
if len(path_dict) < 3:
176+
raise Http404Error()
175177
package = path_dict[0]
176178
version = path_dict[1]
177179
patch = '/'.join(path_dict[2:])

debsources/app/views.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from debsources.excepts import (
2727
Http500Error, Http404Error, Http404ErrorSuggestions, Http403Error,
2828
InvalidPackageOrVersionError, Http404MissingCopyright,
29-
MissingCopyrightField)
29+
MissingCopyrightField, CopyrightValueError)
3030
from debsources.models import Package, SuiteAlias
3131
import debsources.query as qry
3232
from debsources.sqla_session import _close_session
@@ -132,8 +132,15 @@ def error_404(self, error):
132132
return render_template('copyright/404_missing.html',
133133
suggestions=suggestions), 404
134134
elif isinstance(error, MissingCopyrightField):
135-
return render_template('copyright/404_missing_copyright.html',
136-
paragraph=error.par)
135+
return render_template('copyright/missing_copyright.html',
136+
paragraph=error.par,
137+
package=error.package,
138+
version=error.version)
139+
elif isinstance(error, CopyrightValueError):
140+
return render_template('copyright/value_error.html',
141+
error=error.error,
142+
package=error.package,
143+
version=error.version)
137144
else:
138145
return render_template('404.html'), 404
139146

debsources/excepts.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,11 @@ def __init__(self, package, version, par):
5454
self.version = version
5555
self.par = par
5656
super(MissingCopyrightField, self).__init__()
57+
58+
59+
class CopyrightValueError(Http404Error):
60+
def __init__(self, package, version, error):
61+
self.package = package
62+
self.version = version
63+
self.error = error
64+
super(CopyrightValueError, self).__init__()

debsources/license_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def get_copyright_header(copyright):
149149
return copyright.header._RestrictedWrapper__data
150150

151151

152-
def parse_copyright_paragraphs_for_html_render(copyright, base_url):
152+
def parse_copyright_paragraphs_html_render(copyright, base_url):
153153
""" Returns list of File objects. If `base_url` is provided
154154
then it creates links to base_url+glob
155155
"""

0 commit comments

Comments
 (0)