Skip to content

Commit 9b8a6cc

Browse files
committed
Fix the license file not found that leads to index error
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent d36dbb1 commit 9b8a6cc

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/attributecode/attrib.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
4949
or None and attribution text is the generated text or None.
5050
"""
5151
rendered = None
52-
error = None
52+
errors = []
5353
template_error = check_template(template)
5454
if template_error:
5555
lineno, message = template_error
5656
error = Error(
5757
CRITICAL,
5858
'Template validation error at line: {lineno}: "{message}"'.format(**locals())
5959
)
60+
errors.append(error)
6061
return error, None
6162

6263
template = jinja2.Template(template)
@@ -79,14 +80,20 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
7980
for lic in licenses_list:
8081
if key in lic.key:
8182
captured = True
83+
break
8284
if not captured or not licenses_list:
8385
name = lic_name
84-
filename = list(about.license_file.value.keys())[index]
86+
if about.license_file.value.keys():
87+
filename = list(about.license_file.value.keys())[index]
88+
text = list(about.license_file.value.values())[index]
89+
else:
90+
error = Error(CRITICAL, 'No license file found for ' + name)
91+
errors.append(error)
92+
break
8593
if about.license_url.value:
8694
url = about.license_url.value[index]
8795
else:
8896
url = ''
89-
text = list(about.license_file.value.values())[index]
9097
license_object = License(key, name, filename, url, text)
9198
licenses_list.append(license_object)
9299
index = index + 1
@@ -182,8 +189,8 @@ def generate(abouts, is_about_input, license_dict, scancode, min_license_score,
182189
tkversion=__version__,
183190
vartext=vartext
184191
)
185-
return error, rendered
186192

193+
return errors, rendered
187194

188195
def get_license_file_key(license_text_name):
189196
if license_text_name.endswith('.LICENSE'):
@@ -256,7 +263,7 @@ def generate_and_save(abouts, is_about_input, license_dict, output_location, sca
256263
)
257264

258265
if rendering_error:
259-
errors.append(rendering_error)
266+
errors.extend(rendering_error)
260267

261268
if rendered:
262269
output_location = add_unc(output_location)

0 commit comments

Comments
 (0)