Skip to content

Commit 768da9b

Browse files
committed
Add 'about_file_path' reference in the error #284
The 'about_file_path' reference is now added along with the error message. In addition, the previous code dedup all the same error for all ABOUT files, such as missing essential field, which is incorrect. If 3 ABOUT files are missing the essential field, such as 'name', we should log this 3 times with reference of which ABOUT files have the issue. Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 3f8f644 commit 768da9b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/attributecode/model.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,7 @@ def collect_inventory(location):
11131113
About objects.
11141114
"""
11151115
errors = []
1116+
dedup_errors = []
11161117
input_location = util.get_absolute(location)
11171118
about_locations = list(util.get_about_locations(input_location))
11181119

@@ -1122,12 +1123,18 @@ def collect_inventory(location):
11221123
for about_loc in about_locations:
11231124
about_file_path = util.get_relative_path(input_location, about_loc)
11241125
about = About(about_loc, about_file_path)
1125-
# Avoid logging duplicated/same errors multiple times
1126-
for about_error in about.errors:
1127-
if not about_error in errors:
1128-
errors.append(about_error)
1126+
# Insert about_file_path reference to the error
1127+
for severity, message in about.errors:
1128+
msg = (about_file_path + ": " + message)
1129+
errors.append(Error(severity, msg))
11291130
abouts.append(about)
1130-
return errors, abouts
1131+
1132+
# Avoid logging duplicated/same errors multiple times
1133+
for about_error in errors:
1134+
if not about_error in dedup_errors:
1135+
dedup_errors.append(about_error)
1136+
1137+
return dedup_errors, abouts
11311138

11321139

11331140
def field_names(abouts, with_paths=True, with_absent=True, with_empty=True):

tests/test_model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,10 +1098,11 @@ def test_collect_inventory_return_errors(self):
10981098
file_path1 = posixpath.join(test_loc, 'distribute_setup.py')
10991099
file_path2 = posixpath.join(test_loc, 'date_test.py')
11001100

1101-
err_msg1 = u'Field about_resource: Path %s not found' % file_path1
1102-
err_msg2 = u'Field about_resource: Path %s not found' % file_path2
1101+
err_msg1 = u'non-supported_date_format.ABOUT: Field about_resource: Path %s not found' % file_path1
1102+
err_msg2 = u'supported_date_format.ABOUT: Field about_resource: Path %s not found' % file_path2
11031103
expected_errors = [
1104-
Error(INFO, u'Field date is not a supported field and is ignored.'),
1104+
Error(INFO, u'non-supported_date_format.ABOUT: Field date is not a supported field and is ignored.'),
1105+
Error(INFO, u'supported_date_format.ABOUT: Field date is not a supported field and is ignored.'),
11051106
Error(CRITICAL, err_msg1),
11061107
Error(CRITICAL, err_msg2)]
11071108
assert sorted(expected_errors) == sorted(errors)

0 commit comments

Comments
 (0)