Skip to content

Commit c547737

Browse files
committed
annotate.py: Temporary debug prints in hunk_tokens_for_type()
Those are intended to find the source of the error that sometimes do appear when using 'diff-annotate from-repo'. File "src/diffannotator/annotate.py", line 1015, in hunk_tokens_for_type result[hunk_line_no] = tokens_list[line_no - 1] ~~~~~~~~~~~^^^^^^^^^^^^^ KeyError: 0
1 parent b09b9da commit c547737

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/diffannotator/annotate.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,19 @@ def hunk_tokens_for_type(self, line_type: Literal['-','+'],
10111011
# NOTE: the first line of the file is line number 1, not 0, according to (uni)diff
10121012
# but self.tokens_for_type(line_type) returns 0-based indexing
10131013
line_no = line.source_line_no if line_type == unidiff.LINE_TYPE_REMOVED else line.target_line_no
1014-
# the first line is 1; the first element has index 0
1015-
result[hunk_line_no] = tokens_list[line_no - 1]
1014+
try:
1015+
# the first line is 1; the first element has index 0
1016+
result[hunk_line_no] = tokens_list[line_no - 1]
1017+
except KeyError as err:
1018+
## DEBUG
1019+
print(f"{err}")
1020+
print(f"{line_no=}")
1021+
print(f"{hunk_line_no=}")
1022+
print(f"{line=}")
1023+
print(f"{hunk=}")
1024+
if tokens_list is not None:
1025+
print(f"{tokens_list.keys()=}")
1026+
raise err
10161027

10171028
return result
10181029

0 commit comments

Comments
 (0)