Skip to content

Commit 261d7d8

Browse files
committed
chore: stricter types
- Add eqwalizer_support and gradualizer plugins - Fix curlmopt() type to include max_total_connections and max_concurrent_streams - Fix encode_body/1 error return type - Fix #req record field types for headers and body - Use unicode:characters_to_binary in error_map/2
1 parent 64d6282 commit 261d7d8

File tree

6 files changed

+36
-20
lines changed

6 files changed

+36
-20
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
name: Erlang/OTP ${{matrix.otp}} / rebar3 ${{matrix.rebar3}}
99
strategy:
1010
matrix:
11-
otp: ['26']
12-
rebar3: ['3.18.0']
11+
otp: ['27']
12+
rebar3: ['3.24.0']
1313

1414
steps:
1515
- uses: actions/checkout@v4
@@ -150,8 +150,8 @@ jobs:
150150
151151
- uses: erlef/setup-beam@v1
152152
with:
153-
otp-version: '26'
154-
rebar3-version: '3.18.0'
153+
otp-version: '27'
154+
rebar3-version: '3.24.0'
155155

156156
- name: Install dependencies
157157
run: |

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
erlang 26.0.2
1+
erlang 27.3.4.6

rebar.config

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
{erl_opts, [debug_info]}.
44

5-
{minimum_otp_vsn, "23.0"}.
5+
{minimum_otp_vsn, "27"}.
66

77
{deps, [
88
{worker_pool, "6.0.1"},
99
{opentelemetry_api, "1.4.0"},
10-
{opentelemetry_api_experimental, "0.5.1"}
10+
{opentelemetry_api_experimental, "0.5.1"},
11+
{eqwalizer_support,
12+
{git_subdir,
13+
"https://github.com/whatsapp/eqwalizer.git",
14+
{tag, "v0.25.3"},
15+
"eqwalizer_support"}}
1116
]}.
1217

1318
{profiles,
@@ -32,7 +37,12 @@
3237
{"freebsd", clean, "gmake -C c_src clean"}]}.
3338

3439
{dialyzer, [
35-
{warnings, [no_return, unmatched_returns, error_handling]},
40+
{warnings, [
41+
no_return,
42+
unmatched_returns,
43+
error_handling,
44+
unknown
45+
]},
3646
{plt_extra_apps, [worker_pool]}
3747
]}.
3848

@@ -44,7 +54,9 @@
4454

4555
{plugins, [rebar3_hex,
4656
rebar3_lint,
47-
{covertool, "2.0.6"}]}.
57+
{covertool, "2.0.6"},
58+
{gradualizer, {git, "https://github.com/josefs/Gradualizer.git", {tag, "0.3.0"}}}
59+
]}.
4860
{cover_enabled, true}.
4961
{cover_export_enabled, true}.
5062
{covertool, [{coverdata_files, ["ct.coverdata"]}]}.

rebar.lock

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{"1.2.0",
2-
[{<<"metrics">>,{pkg,<<"metrics">>,<<"2.5.0">>},0},
2+
[{<<"eqwalizer_support">>,
3+
{git_subdir,"https://github.com/whatsapp/eqwalizer.git",
4+
{ref,"0f514eb3893fa7070835c83ecb49fbea31b0426d"},
5+
"eqwalizer_support"},
6+
0},
37
{<<"opentelemetry_api">>,{pkg,<<"opentelemetry_api">>,<<"1.4.0">>},0},
48
{<<"opentelemetry_api_experimental">>,
59
{pkg,<<"opentelemetry_api_experimental">>,<<"0.5.1">>},
610
0},
711
{<<"worker_pool">>,{pkg,<<"worker_pool">>,<<"6.0.1">>},0}]}.
812
[
913
{pkg_hash,[
10-
{<<"metrics">>, <<"268D218D56529CB5F070D74BBFC3AF64C668379B5B18FAFDA88959442F790C57">>},
1114
{<<"opentelemetry_api">>, <<"63CA1742F92F00059298F478048DFB826F4B20D49534493D6919A0DB39B6DB04">>},
1215
{<<"opentelemetry_api_experimental">>, <<"1B5AFACFCBD0834390336C845BC8AE08C8CF0D69BBED72EE53D178798B93E074">>},
1316
{<<"worker_pool">>, <<"CA262C2DFB3B4AF661B206C82065D86F83922B7227508AA6E0BC34D3E5AE5135">>}]},
1417
{pkg_hash_ext,[
15-
{<<"metrics">>, <<"AE061938C8C3BDE97D17BE9A792B63E15C1E1EFFE16598AB87A62384F5F3714B">>},
1618
{<<"opentelemetry_api">>, <<"3DFBBFAA2C2ED3121C5C483162836C4F9027DEF469C41578AF5EF32589FCFC58">>},
1719
{<<"opentelemetry_api_experimental">>, <<"10297057EADA47267D4F832011BECEF07D25690E6BF91FEBCCFC4E740DBA1A6F">>},
1820
{<<"worker_pool">>, <<"772E12CCB26909EA7F804B52E86E733DF66BB8150F683B591B0A762196494C74">>}]}

src/katipo.erl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@
268268
%% curlmopt_content_length_penalty_size |
269269
%% curlmopt_max_host_connections |
270270
max_pipeline_length |
271-
curlmopt_max_total_connections |
271+
max_total_connections |
272+
max_concurrent_streams |
272273
%% curlmopt_maxconnects |
273274
pipelining.
274275
%% curlmopt_pipelining_site_bl |
@@ -441,9 +442,9 @@
441442
-record(req, {
442443
method = ?GET :: method_int(),
443444
url :: undefined | binary(),
444-
headers = [] :: headers(),
445+
headers = [] :: [binary()],
445446
cookiejar = [] :: cookiejar(),
446-
body = <<>> :: body(),
447+
body = <<>> :: iodata(),
447448
connecttimeout_ms = ?DEFAULT_REQ_TIMEOUT :: pos_integer(),
448449
followlocation = ?FOLLOWLOCATION_FALSE :: integer(),
449450
ssl_verifyhost = ?SSL_VERIFYHOST_TRUE :: integer(),
@@ -830,7 +831,7 @@ encode_body([{_, _} | _] = KVs) ->
830831
encode_body(Body) when is_binary(Body) orelse is_list(Body) ->
831832
{ok, Body};
832833
encode_body(Body) ->
833-
{error, Body}.
834+
{error, {invalid_body, Body}}.
834835

835836
get_mopts(Opts) ->
836837
L = lists:filtermap(fun mopt_supported/1, Opts),
@@ -1028,5 +1029,6 @@ check_opts(Opts) when is_map(Opts) ->
10281029
error_map(Code, Message) when is_atom(Code) andalso is_binary(Message) ->
10291030
#{code => Code, message => Message};
10301031
error_map(Code, Message) when is_atom(Code) ->
1031-
BinaryMessage = iolist_to_binary(io_lib:format("~p", [Message])),
1032+
Chars = io_lib:format("~p", [Message]),
1033+
BinaryMessage = unicode:characters_to_binary(Chars),
10321034
error_map(Code, BinaryMessage).

test/katipo_SUITE.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ post_body_qs_vals(Config) ->
284284
?assertEqual(<<"!@#$%^&*()">>, maps:get(<<"data">>, Json)).
285285

286286
post_body_bad(_) ->
287-
Message = [{body, should_not_be_an_atom}],
287+
Message = [{body, {invalid_body, should_not_be_an_atom}}],
288288
BinaryMessage = iolist_to_binary(io_lib:format("~p", [Message])),
289289
%% URL doesn't matter - request fails during option validation
290290
{error, #{code := bad_opts, message := BinaryMessage}} =
@@ -800,13 +800,13 @@ port_death(Config) ->
800800
{ok, _} = katipo_pool:start(PoolName, PoolSize),
801801
WorkerName = wpool_pool:best_worker(PoolName),
802802
WorkerPid = whereis(WorkerName),
803-
{state, _, katipo, {state, Port, _}, _} = sys:get_state(WorkerPid),
803+
{state, _, _, {state, Port, _}, _} = sys:get_state(WorkerPid),
804804
true = port_command(Port, <<"hdfjkshkjsdfgjsgafdjgsdjgfj">>),
805805
Fun = fun() ->
806806
WorkerName2 = wpool_pool:best_worker(PoolName),
807807
WorkerPid2 = whereis(WorkerName2),
808808
case sys:get_state(WorkerPid2) of
809-
{state, _, katipo, {state, Port2, _}, _} when Port =/= Port2 ->
809+
{state, _, _, {state, Port2, _}, _} when Port =/= Port2 ->
810810
{ok, #{status := 200}} =
811811
katipo:get(PoolName, Url, BaseOpts),
812812
true

0 commit comments

Comments
 (0)