Skip to content

Commit d25aacb

Browse files
committed
Simplify offset handling in TokenMissingError
1 parent 106539b commit d25aacb

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

lib/elixir/lib/exception.ex

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,20 +1298,11 @@ defmodule TokenMissingError do
12981298
{lines, total_trimmed_lines} = handle_trailing_newlines(snippet)
12991299
end_line = end_line - total_trimmed_lines
13001300

1301-
# For cases such as inside ExUnit doctests, our snippet is tiny, containing
1302-
# only the lines in the doctest, but the `line` and `end_line` we receive
1303-
# are still tied to the whole file.
1304-
#
1305-
# In these situations we use `line_offset` to treat `line` as 1 for
1306-
# operating on the snippet, while retaining the original line information.
1307-
should_use_line_offset? = is_nil(Enum.at(lines, end_line - 1))
1308-
13091301
end_column =
1310-
if should_use_line_offset? do
1311-
fetch_line_length(lines, end_line - line_offset - 1)
1312-
else
1313-
fetch_line_length(lines, end_line - 1)
1314-
end
1302+
lines
1303+
|> Enum.fetch!(end_line - line_offset - 1)
1304+
|> String.length()
1305+
|> Kernel.+(1)
13151306

13161307
start_pos = {line, column}
13171308
end_pos = {end_line, end_column}
@@ -1356,13 +1347,6 @@ defmodule TokenMissingError do
13561347
{lines, total_trimmed_newlines}
13571348
end
13581349

1359-
defp fetch_line_length(lines, index) do
1360-
lines
1361-
|> Enum.fetch!(index)
1362-
|> String.length()
1363-
|> Kernel.+(1)
1364-
end
1365-
13661350
defp format_message(file, line, column, message) do
13671351
location = Exception.format_file_line_column(Path.relative_to_cwd(file), line, column)
13681352
"token missing on " <> location <> "\n" <> message

0 commit comments

Comments
 (0)