From ef97078d022b0e36e0c8b2e8e99b760df4809ea5 Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Mon, 1 Jul 2024 19:47:58 +0100 Subject: [PATCH] Fixes for Dialyzer (#338) * 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 97471c27c19d21accb5a5df32a098e621d4f1a47. * Be more strict, again * Bump hex_core (0.10.2 to 0.10.3) to support our Dialyzer fixes --- .github/workflows/ci.yml | 14 ++++++++++++-- rebar.config | 2 +- rebar.lock | 6 +++--- src/rebar3_hex_build.erl | 25 ++++--------------------- src/rebar3_hex_client.erl | 11 +++++++---- src/rebar3_hex_organization.erl | 1 - src/rebar3_hex_publish.erl | 2 -- src/rebar3_hex_retire.erl | 2 -- src/rebar3_hex_user.erl | 8 +------- 9 files changed, 28 insertions(+), 43 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b13d54e6..6687bd3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/rebar.config b/rebar.config index 64da2f2c..9b377b55 100644 --- a/rebar.config +++ b/rebar.config @@ -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, [ diff --git a/rebar.lock b/rebar.lock index 9aa6c4ab..02c30cb5 100644 --- a/rebar.lock +++ b/rebar.lock @@ -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">>}]} ]. diff --git a/src/rebar3_hex_build.erl b/src/rebar3_hex_build.erl index 016003aa..d6e6c0c7 100644 --- a/src/rebar3_hex_build.erl +++ b/src/rebar3_hex_build.erl @@ -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} -> @@ -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) -> @@ -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()) -> diff --git a/src/rebar3_hex_client.erl b/src/rebar3_hex_client.erl index 016d9984..c0f446d1 100644 --- a/src/rebar3_hex_client.erl +++ b/src/rebar3_hex_client.erl @@ -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, <>, Perms) -> @@ -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) -> @@ -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 @@ -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). diff --git a/src/rebar3_hex_organization.erl b/src/rebar3_hex_organization.erl index 6767e85e..85c2ba86 100644 --- a/src/rebar3_hex_organization.erl +++ b/src/rebar3_hex_organization.erl @@ -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), diff --git a/src/rebar3_hex_publish.erl b/src/rebar3_hex_publish.erl index 9962ff58..33c5b98f 100644 --- a/src/rebar3_hex_publish.erl +++ b/src/rebar3_hex_publish.erl @@ -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), @@ -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), diff --git a/src/rebar3_hex_retire.erl b/src/rebar3_hex_retire.erl index 88915b5a..07b2277f 100644 --- a/src/rebar3_hex_retire.erl +++ b/src/rebar3_hex_retire.erl @@ -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 @@ -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, diff --git a/src/rebar3_hex_user.erl b/src/rebar3_hex_user.erl index 34429593..3bb6cba3 100644 --- a/src/rebar3_hex_user.erl +++ b/src/rebar3_hex_user.erl @@ -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]), @@ -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, _} -> @@ -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}} -> @@ -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"]).