Skip to content

Commit 9f5be21

Browse files
Merge pull request #3 from ipdata/claude/verify-all-tests-YVXdw
Fix dialyzer underspecs warnings across all modules
2 parents 2c55aaf + 7b8d1a5 commit 9f5be21

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/ipdata.erl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
timeout => pos_integer()
4646
}.
4747

48+
-type lookup_error() :: {json_error, term()}
49+
| {request_failed, term()}
50+
| {http_error, non_neg_integer(), binary()}.
51+
52+
-type bulk_error() :: lookup_error()
53+
| {invalid_input, binary()}.
54+
55+
%% bulk/2 delegates to bulk/3 whose invalid_input messages are constant
56+
%% binaries; dialyzer infers their exact byte-size which is narrower than
57+
%% binary(). There is no readable type for "binary of at least N bytes".
58+
-dialyzer({no_underspecs, bulk/2}).
59+
4860
-define(DEFAULT_ENDPOINT, <<"https://api.ipdata.co">>).
4961
-define(EU_ENDPOINT, <<"https://eu-api.ipdata.co">>).
5062
-define(DEFAULT_TIMEOUT, 5000).
@@ -86,7 +98,7 @@ new(_ApiKey, _Opts) ->
8698
%% @doc Look up the IP address of the calling machine.
8799
%% @end
88100
%%--------------------------------------------------------------------
89-
-spec lookup(Client :: client()) -> {ok, map()} | {error, term()}.
101+
-spec lookup(Client :: client()) -> {ok, #{atom() | binary() => term()}} | {error, lookup_error()}.
90102
lookup(Client) ->
91103
lookup(Client, <<>>, []).
92104

@@ -97,7 +109,7 @@ lookup(Client) ->
97109
%% @end
98110
%%--------------------------------------------------------------------
99111
-spec lookup(Client :: client(), IP :: binary()) ->
100-
{ok, map()} | {error, term()}.
112+
{ok, #{atom() | binary() => term()}} | {error, lookup_error()}.
101113
lookup(Client, IP) ->
102114
lookup(Client, IP, []).
103115

@@ -114,7 +126,7 @@ lookup(Client, IP) ->
114126
%% @end
115127
%%--------------------------------------------------------------------
116128
-spec lookup(Client :: client(), IP :: binary(), Fields :: [binary()]) ->
117-
{ok, map()} | {error, term()}.
129+
{ok, #{atom() | binary() => term()}} | {error, lookup_error()}.
118130
lookup(#{api_key := ApiKey, endpoint := Endpoint, timeout := Timeout}, IP, Fields) ->
119131
Path = case IP of
120132
<<>> -> <<>>;
@@ -130,7 +142,7 @@ lookup(#{api_key := ApiKey, endpoint := Endpoint, timeout := Timeout}, IP, Field
130142
%% @end
131143
%%--------------------------------------------------------------------
132144
-spec bulk(Client :: client(), IPs :: [binary()]) ->
133-
{ok, [map()]} | {error, term()}.
145+
{ok, [map()]} | {error, bulk_error()}.
134146
bulk(Client, IPs) ->
135147
bulk(Client, IPs, []).
136148

@@ -147,7 +159,7 @@ bulk(Client, IPs) ->
147159
%% @end
148160
%%--------------------------------------------------------------------
149161
-spec bulk(Client :: client(), IPs :: [binary()], Fields :: [binary()]) ->
150-
{ok, [map()]} | {error, term()}.
162+
{ok, [map()]} | {error, bulk_error()}.
151163
bulk(_Client, [], _Fields) ->
152164
{error, {invalid_input, <<"At least one IP address is required">>}};
153165
bulk(_Client, IPs, _Fields) when length(IPs) > ?MAX_BULK_IPS ->
@@ -166,7 +178,7 @@ resolve_endpoint(eu) -> ?EU_ENDPOINT;
166178
resolve_endpoint(URL) when is_binary(URL) -> URL.
167179

168180
-spec build_url(Endpoint :: binary(), Path :: binary(),
169-
ApiKey :: binary(), Fields :: [binary()]) -> binary().
181+
ApiKey :: binary(), Fields :: [binary()]) -> <<_:64, _:_*8>>.
170182
build_url(Endpoint, Path, ApiKey, Fields) ->
171183
Base = <<Endpoint/binary, Path/binary, "?api-key=", ApiKey/binary>>,
172184
case Fields of

src/ipdata_http.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ http_options(Timeout) ->
6262
{connect_timeout, Timeout},
6363
{ssl, ssl_options()}].
6464

65-
-spec ssl_options() -> list().
65+
-spec ssl_options() -> [ssl:tls_client_option()].
6666
ssl_options() ->
6767
[{verify, verify_peer},
6868
{depth, 100},

src/ipdata_sup.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ start_link() ->
2626
%% @doc Initialize the supervisor with no children.
2727
%% @end
2828
%%--------------------------------------------------------------------
29-
-spec init(term()) -> {ok, {supervisor:sup_flags(), [supervisor:child_spec()]}}.
29+
-spec init([]) -> {ok, {supervisor:sup_flags(), []}}.
3030
init([]) ->
3131
SupFlags = #{strategy => one_for_one,
3232
intensity => 1,

0 commit comments

Comments
 (0)