Skip to content

Commit 8fd88ee

Browse files
committed
fix crash when invalid error is raised
1 parent 547f363 commit 8fd88ee

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

mypy/errors.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ def format_messages(
987987
a.append(s)
988988
if self.options.pretty:
989989
# Add source code fragment and a location marker.
990-
if severity == "error" and source_lines and line > 0:
990+
if severity == "error" and source_lines and len(source_lines) >= line > 0:
991991
source_line = source_lines[line - 1]
992992
source_line_expanded = source_line.expandtabs()
993993
if column < 0:
@@ -1201,7 +1201,10 @@ def render_messages(
12011201
)
12021202
)
12031203
src = (
1204-
file == current_file and source_lines and e.line > 0 and source_lines[e.line - 1]
1204+
file == current_file
1205+
and source_lines
1206+
and len(source_lines) >= e.line > 0
1207+
and source_lines[e.line - 1]
12051208
) or ""
12061209
# when there is no column, but we still want an ide to show an error
12071210
if e.column == -1 and self.options.show_error_end:

0 commit comments

Comments
 (0)