Skip to content

Commit b14bb7d

Browse files
committed
Fixed #187 - display line number for "Invalid line" error
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 60e0c31 commit b14bb7d

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/attributecode/model.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -918,13 +918,9 @@ def hydrate(self, fields, use_mapping=False, mapping_file=None):
918918
try:
919919
setattr(self, name, custom_field)
920920
except:
921-
# The intended captured error message should display
922-
# the line number of where the invalid line is,
923-
# but I am not able to get the line number from
924-
# the original code. By-passing the line number
925-
# for now.
926-
# msg = u'Invalid line: %(line)d: %(orig_name)r'
927-
msg = u'Invalid line: %(orig_name)r: ' % locals()
921+
# According to https://stackoverflow.com/questions/533048/how-to-log-source-file-name-and-line-number-in-python/44401529 ,
922+
# we use `lineno` instead of `line` to get the line number
923+
msg = u'Invalid line: %(lineno)d: %(orig_name)r' % locals()
928924
msg += u'%s' % custom_field.value
929925
errors.append(Error(CRITICAL, msg))
930926
return errors

0 commit comments

Comments
 (0)