Skip to content

Commit 67f4768

Browse files
committed
Alternative stacktrace filtering implementation
1 parent 8c16861 commit 67f4768

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/ecto/adapters/sql.ex

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,19 +1438,21 @@ defmodule Ecto.Adapters.SQL do
14381438
) :: Exception.stacktrace()
14391439
def first_non_ecto_stacktrace(stacktrace, %{repo: repo}, size) do
14401440
stacktrace
1441+
|> first_non_ecto_entries(repo, size, size, [])
14411442
|> Enum.reverse()
1442-
|> last_non_ecto_entries(repo, [])
1443-
|> Enum.take(size)
14441443
end
14451444

1446-
defp last_non_ecto_entries([{mod, _, _, _} | _], repo, acc)
1445+
defp first_non_ecto_entries([{mod, _, _, _} | rest], repo, size, _, _)
14471446
when mod == repo or mod in @repo_modules,
1448-
do: acc
1447+
do: first_non_ecto_entries(rest, repo, size, size, [])
14491448

1450-
defp last_non_ecto_entries([entry | rest], repo, acc),
1451-
do: last_non_ecto_entries(rest, repo, [entry | acc])
1449+
defp first_non_ecto_entries([_ | rest], repo, size, 0, acc),
1450+
do: first_non_ecto_entries(rest, repo, size, 0, acc)
14521451

1453-
defp last_non_ecto_entries([], _, acc), do: acc
1452+
defp first_non_ecto_entries([], _, _, _, acc), do: acc
1453+
1454+
defp first_non_ecto_entries([entry | rest], repo, size, pending, acc),
1455+
do: first_non_ecto_entries(rest, repo, size, pending - 1, [entry | acc])
14541456

14551457
## Connection helpers
14561458

0 commit comments

Comments
 (0)