Skip to content

Commit 3b95a37

Browse files
committed
Make HTTPoison adapter compile only when HTTPoison is loaded
The adapter module references %HTTPoison.Response{} and %HTTPoison.Error{} structs at compile time, so it could not be compiled in a consumer project that drops httpoison from its deps — even though mix.exs already declares httpoison as optional: true. Wrap the defmodule block in Code.ensure_loaded?(HTTPoison) so the module is only defined when HTTPoison is actually available. Funkspector's own test matrix still pulls HTTPoison transitively (optional deps are included in the package's own build), so test.adapters keeps exercising both adapters.
1 parent 1ab6710 commit 3b95a37

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/funkspector/http/adapters/httpoison.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
if Code.ensure_loaded?(HTTPoison) do
12
defmodule Funkspector.HTTP.Adapters.HTTPoison do
23
@moduledoc """
34
Opt-in Funkspector HTTP adapter, backed by
45
[HTTPoison](https://hex.pm/packages/httpoison) on top of hackney.
56
7+
Compiled only when the `:httpoison` dependency is actually present in the
8+
consuming project — `httpoison` is declared `optional: true` in
9+
`funkspector`'s `mix.exs`, so projects that stick with the default Req
10+
adapter do not need to pull it in. When HTTPoison is missing the module
11+
is simply not defined; selecting it as the adapter in that case fails
12+
with `UndefinedFunctionError` at call time, which is the desired
13+
behaviour for an explicit opt-in.
14+
615
This is the historical Funkspector HTTP path, preserved for users who
716
cannot — or do not want to — move to Req yet. The defaults here match
817
the pre-2.0 behavior:
@@ -101,3 +110,4 @@ defmodule Funkspector.HTTP.Adapters.HTTPoison do
101110
end
102111
end
103112
end
113+
end

0 commit comments

Comments
 (0)