Skip to content

Commit

Permalink
Fixes for Dialyzer (#338)
Browse files Browse the repository at this point in the history
* Prepare to fix as many Dialyzer issues as possible

* Remove intermediate function that seems to serve no purpose

Whatever hex_tarball:create_docs(Files) returns
         create_docs_tarball also returns

:-)

* Don't code for return values that cannot happen

As per hex_core

* Only run Dialyzer for most recent OTP version

* Bump hex_core from 0.10.1 to 0.10.2

Takes care of a Dialyzer issue

* Respect the remote spec

atoms, not binaries

* Manipulate similar elements in similar places

* Revert "Respect the remote spec"

This reverts commit 97471c2.

* Be more strict, again

* Bump hex_core (0.10.2 to 0.10.3) to support our Dialyzer fixes
  • Loading branch information
paulo-ferraz-oliveira authored Jul 1, 2024
1 parent b0860b3 commit ef97078
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 43 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ jobs:
runs-on: ubuntu-24.04
strategy:
matrix:
otp: ['25', '26', '27']
rebar3: ['3.23.0']
include:
- otp: 27
os: ubuntu-24.04
rebar3: 3.23
dialyzer: true
- otp: 26
os: ubuntu-24.04
rebar3: 3.23
- otp: 25
os: ubuntu-24.04
rebar3: 3.23
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
Expand All @@ -23,6 +32,7 @@ jobs:
rebar3-version: ${{matrix.rebar3}}
- name: Static analysis
run: rebar3 dialyzer
if: ${{ matrix.dialyzer == true }}
- name: Common Tests
run: rebar3 ct
- name: Code coverage
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{project_plugins, [{covertool, "2.0.6"}, {rebar3_ex_doc, "0.2.23"}, {rebar3_hank, "1.4.0"}]}.

{deps, [{hex_core, "0.10.1"}, {verl, "1.1.1"}]}.
{deps, [{hex_core, "0.10.3"}, {verl, "1.1.1"}]}.

{profiles, [
{test, [
Expand Down
6 changes: 3 additions & 3 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{"1.2.0",
[{<<"hex_core">>,{pkg,<<"hex_core">>,<<"0.10.1">>},0},
[{<<"hex_core">>,{pkg,<<"hex_core">>,<<"0.10.3">>},0},
{<<"verl">>,{pkg,<<"verl">>,<<"1.1.1">>},0}]}.
[
{pkg_hash,[
{<<"hex_core">>, <<"A2AF5C8D9A00A2E3F4337EFD278384B3F5E538EBE9EC541FAA0709BEAC9EA0C5">>},
{<<"hex_core">>, <<"7DC866CA8F5830566AACEF141BDDE4F1D61F687407C7070611C349E983F185D2">>},
{<<"verl">>, <<"98F3EC48B943AA4AE8E29742DE86A7CD752513687911FE07D2E00ECDF3107E45">>}]},
{pkg_hash_ext,[
{<<"hex_core">>, <<"FD39152D342B7FD4CE3F803AC7F084B60D1BC9BF13E707E35DBDCE266FBB65F0">>},
{<<"hex_core">>, <<"BC7C2B6CEB99E29550F74234952AD3B8153E6F2DBC38892BD0FF46043BE073F5">>},
{<<"verl">>, <<"0925E51CD92A0A8BE271765B02430B2E2CFF8AC30EF24D123BD0D58511E8FB18">>}]}
].
25 changes: 4 additions & 21 deletions src/rebar3_hex_build.erl
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ create_docs(State, Repo, App) ->
create_docs(State, Repo, App, #{doc_dir => undefined}).

%% @private
-dialyzer({nowarn_function, create_docs/4}).
create_docs(State, Repo, App, Args) ->
case maybe_gen_docs(State, Repo, App, Args) of
{ok, DocDir} ->
Expand All @@ -496,23 +495,19 @@ create_docs(State, Repo, App, Args) ->
PkgName = rebar_utils:to_list(proplists:get_value(pkg_name, AppDetails, Name)),
OriginalVsn = rebar_app_info:original_vsn(App),
Vsn = rebar_utils:vcs_vsn(App, OriginalVsn, State),
case create_docs_tarball(Files) of
case hex_tarball:create_docs(Files) of
{ok, Tarball} ->
{ok, #{
type => docs, tarball => Tarball, name => binarify(PkgName), version => binarify(Vsn)
}};
{error, Reason} ->
{error, hex_tarball:format_error(Reason)};
Err ->
Err
{error, hex_tarball:format_error(Reason)}
end;
false ->
{error, missing_doc_index}
end;
{error, _} = Err ->
Err;
Err ->
{error, Err}
Err
end.

maybe_gen_docs(_State, _Repo, App, #{doc_dir := DocDir}) when is_list(DocDir) ->
Expand Down Expand Up @@ -591,24 +586,12 @@ binarify({Key, Value}) ->
binarify(Term) ->
Term.

-dialyzer({nowarn_function, create_package_tarball/2}).
create_package_tarball(Metadata, Files) ->
case hex_tarball:create(Metadata, Files) of
{ok, #{tarball := Tarball, inner_checksum := _Checksum}} ->
Tarball;
{error, Reason} ->
{error, hex_tarball:format_error(Reason)};
Error ->
Error
end.

-dialyzer({nowarn_function, create_docs_tarball/1}).
create_docs_tarball(Files) ->
case hex_tarball:create_docs(Files) of
{ok, Tarball} ->
{ok, Tarball};
Error ->
Error
{error, hex_tarball:format_error(Reason)}
end.

-spec to_atom(atom() | string() | binary() | integer() | float()) ->
Expand Down
11 changes: 7 additions & 4 deletions src/rebar3_hex_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ reset_password(HexConfig, User) ->
response(Res).

me(HexConfig) ->
Res = hex_api_user:me(HexConfig),
Res = hex_api_user:me(to_hex_core_config(HexConfig)),
response(Res).

key_add(HexConfig, <<KeyName/binary>>, Perms) ->
Expand Down Expand Up @@ -69,11 +69,11 @@ key_delete_all(HexConfig) ->
response(Res).

test_key(HexConfig, Perms) ->
Res = hex_api_auth:test(HexConfig, Perms),
Res = hex_api_auth:test(to_hex_core_config(HexConfig), Perms),
response(Res).

publish(HexConfig, Tarball, Opts) ->
Res = hex_api_release:publish(HexConfig, Tarball, Opts),
Res = hex_api_release:publish(to_hex_core_config(HexConfig), Tarball, Opts),
response(Res).

delete_release(HexConfig, Name, Version) ->
Expand All @@ -95,7 +95,6 @@ delete_docs(Config, Name, Version) ->
Res = hex_api:delete(Config, ["packages", Name, "releases", Version, "docs"]),
response(Res).

-dialyzer({nowarn_function, retire/5}).
retire(Config, Package, Version, Reason, Message) ->
Msg = #{<<"reason">> => Reason,
<<"message">> => Message
Expand Down Expand Up @@ -161,3 +160,7 @@ join_lists(Sep, List) ->

to_binary(Subject) ->
rebar_utils:to_binary(Subject).

to_hex_core_config(#{name := Name} = HexConfig) ->
NewHexConfig = HexConfig#{repo_name := Name},
maps:remove(name, NewHexConfig).
1 change: 0 additions & 1 deletion src/rebar3_hex_organization.erl
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ format_error({get_repo_by_name, {error,{not_valid_repo,ParentName}}}) ->
format_error(Reason) ->
rebar3_hex_error:format_error(Reason).

-dialyzer({nowarn_function, auth/2}).
-spec auth(rebar_state:t(), binary()) -> {ok, rebar_state:t()}.
auth(State, RepoName) ->
{Opts, _} = rebar_state:command_parsed_args(State),
Expand Down
2 changes: 0 additions & 2 deletions src/rebar3_hex_publish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ handle_task(#{args := #{task := undefined, app := AppName}, apps := Apps, multi
handle_task(_) ->
?RAISE(bad_command).

-dialyzer({nowarn_function, publish/4}).
publish(State, Repo, App, Args) ->
maybe_warn_about_doc_config(State, Repo),
HexConfig = rebar3_hex_config:get_hex_config(?MODULE, Repo, write),
Expand All @@ -399,7 +398,6 @@ publish(State, Repo, App, Args) ->
%%% package publishing and related functions
%%% ===================================================================

-dialyzer({nowarn_function, publish_package/4}).
publish_package(State, Repo, App, Args) ->
assert_valid_app(State, App),
Package = create_package(State, App),
Expand Down
2 changes: 0 additions & 2 deletions src/rebar3_hex_retire.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ init(State) ->
{ok, State1}.

%% @private
-dialyzer({no_return, do/1}).
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, {?MODULE, rebar3_hex_config:repo_error()}}.
do(State) ->
case rebar3_hex_config:repo(State) of
Expand Down Expand Up @@ -125,7 +124,6 @@ format_error(bad_command) ->
format_error(Reason) ->
rebar3_hex_error:format_error(Reason).

-dialyzer({nowarn_function, retire/6}).
retire(State, PkgName, Version, Repo, RetireReason, RetireMessage) ->
HexConfig = rebar3_hex_config:get_hex_config(?MODULE, Repo, write),
Msg = #{<<"reason">> => RetireReason,
Expand Down
8 changes: 1 addition & 7 deletions src/rebar3_hex_user.erl
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,12 @@ handle_task(#{args := #{task := key, fetch := true, key_name := KeyName}} = Task
handle_task(_) ->
?RAISE(bad_command).

-dialyzer({no_fail_call, whoami/2}).
whoami(#{name := Name} = Repo, State) ->
case maps:get(read_key, Repo, undefined) of
undefined ->
?RAISE(not_authenticated);
ReadKey ->
case rebar3_hex_client:me(maps:remove(name, Repo#{api_key => ReadKey})) of
case rebar3_hex_client:me(Repo#{api_key => ReadKey}) of
{ok, #{<<"username">> := Username,
<<"email">> := Email}} ->
rebar3_hex_io:say("~ts : ~ts (~ts)", [Name, Username, Email]),
Expand Down Expand Up @@ -436,7 +435,6 @@ confirm_password(Type, Fun, ExpectedPw, MaxRetries) ->
do_get_password(Type, Fun, MaxRetries - 1)
end.

-dialyzer({no_fail_call, create_user/5}).
create_user(Username, Email, Password, Repo, State) ->
case rebar3_hex_client:create_user(Repo, Username, Password, Email) of
{ok, _} ->
Expand Down Expand Up @@ -493,8 +491,6 @@ decrypt_write_key(Username, LocalPassword, Key, MaxRetries) ->
end.
-endif.

-dialyzer({nowarn_function, generate_key/3}).
%%-dialyzer({nowarn_function, hex_api_key:add/3}).
generate_key(HexConfig, KeyName, Perms) ->
case rebar3_hex_key:generate(HexConfig, KeyName, Perms) of
{ok, #{<<"secret">> := Secret}} ->
Expand All @@ -512,11 +508,9 @@ hostname() ->
api_key_name() ->
rebar_utils:to_binary(hostname()).

-dialyzer({nowarn_function, api_key_name/1}).
api_key_name(Postfix) ->
rebar_utils:to_binary([hostname(), "-api-", Postfix]).

-dialyzer({nowarn_function, repos_key_name/0}).
repos_key_name() ->
rebar_utils:to_binary([hostname(), "-repositories"]).

Expand Down

0 comments on commit ef97078

Please sign in to comment.