Skip to content

Commit

Permalink
Keep location in HTTPoison.Base.__using__/1
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Wilson authored and edgurgel committed Nov 7, 2023
1 parent 5920e19 commit 24a3908
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/httpoison/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ defmodule HTTPoison.Base do
@type params :: Request.params()

defmacro __using__(_) do
quote do
quote location: :keep do
@behaviour HTTPoison.Base

@type request :: HTTPoison.Base.request()
Expand Down
16 changes: 13 additions & 3 deletions test/httpoison_base_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ defmodule HTTPoisonBaseTest do
assert HTTPoison.get("http://localhost") == {:error, %HTTPoison.Error{reason: reason}}
end

test "stack trace preserved on error" do
expect(:hackney, :request, fn _, _, _, _, _ -> {:error, {:error, "whatevs"}} end)

HTTPoison.get!("http://localhost")
rescue
_e ->
[{HTTPoison, :request!, 5, file_line} | _] = __STACKTRACE__
assert {:ok, ~c"lib/httpoison/base.ex"} = Keyword.fetch(file_line, :file)
end

test "passing connect_timeout option" do
expect(:hackney, :request, fn
:post, "http://localhost", [], "body", [connect_timeout: 12345] ->
Expand Down Expand Up @@ -221,7 +231,7 @@ defmodule HTTPoisonBaseTest do
[
socks5_pass: "secret",
socks5_user: "user",
proxy: {:socks5, 'localhost', 1080}
proxy: {:socks5, ~c"localhost", 1080}
] ->
{:ok, 200, "headers", :client}
end)
Expand All @@ -232,7 +242,7 @@ defmodule HTTPoisonBaseTest do
"localhost",
"body",
[],
proxy: {:socks5, 'localhost', 1080},
proxy: {:socks5, ~c"localhost", 1080},
socks5_user: "user",
socks5_pass: "secret"
) ==
Expand All @@ -246,7 +256,7 @@ defmodule HTTPoisonBaseTest do
headers: [],
method: :post,
options: [
proxy: {:socks5, 'localhost', 1080},
proxy: {:socks5, ~c"localhost", 1080},
socks5_user: "user",
socks5_pass: "secret"
],
Expand Down

0 comments on commit 24a3908

Please sign in to comment.