hexpm / hex

Package manager for the Erlang VM

Home Page:https://hex.pm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when using repo tasks after fresh install

juanazam opened this issue · comments

Hello! Thanks for all the hard work on Hex.

Environment Mac OSX Big Sur (11.5.2 )

Elixir 1.13.2
Erlang 24.1.7 (installed using openssl@1.1 via brew)

When running mix hex.repo list using the latest hex version, I get the following error:

** (FunctionClauseError) no function clause matching in :public_key.pem_decode/1    
    
    The following arguments were given to :public_key.pem_decode/1:
    
        # 1
        :ok
    
    (public_key 1.11) public_key.erl:169: :public_key.pem_decode/1
    (hex 1.0.1) lib/mix/tasks/hex.repo.ex:207: Mix.Tasks.Hex.Repo.show_public_key/1
    (hex 1.0.1) lib/mix/tasks/hex.repo.ex:258: Mix.Tasks.Hex.Repo.show/2
    (mix 1.13.2) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
    (mix 1.13.2) lib/mix/cli.ex:84: Mix.CLI.run_task/2

Not sure how can this happen but it seems that here:

https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.repo.ex#L168

config[:public_key]

Contains :ok, so when running

https://github.com/hexpm/hex/blob/main/lib/mix/tasks/hex.repo.ex#L207

:public_key.pem_decode(public_key)

Errors out because public_key is :ok

Any ideas on why this may be happening?

Thanks!

Did you add any organisations or repositories? If something went wrong then, that'd explain it. Check out your ~/.hex/hex.config if something seems incorrect there. If the problem is there, best to remove the config and re-auth and re-add orgs/repos.

@wojtekmach thanks for you reply, after removing that file mix hex.repo list works. But the problem persists while following oban's installation

When running

mix hex.repo add oban https://getoban.pro/repo \
    --fetch-public-key $OBAN_KEY_FINGERPRINT \
    --auth-key $OBAN_LICENSE_KEY

Results in

11:23:05.672 [notice] TLS :client: In state :certify at ssl_handshake.erl:1882 generated CLIENT ALERT: Fatal - Certificate Expired

Downloading public key failed
{:failed_connect, [{:to_address, {'getoban.pro', 443}}, {:inet, [:inet], {:tls_alert, {:certificate_expired, 'TLS client: In state certify at ssl_handshake.erl:1882 generated CLIENT ALERT: Fatal - Certificate Expired\n'}}}]}

And ~/.hex.config to be pupulated with

{'$repos',#{<<"oban">> =>
                #{auth_key => <<"XXXXXXXXXXXX">>,
                  fetch_public_key =>
                      <<"XXXXXXXXXXXXXXX">>,
                  public_key => ok,url => <<"https://getoban.pro/repo">>}}}.

Basically an entry is added and public_key for that entry is ok

Which results in mix hex.repo list not working again.

Not sure if this is a hex issue or an oban issue.

...
fetch_public_key => <<"XXXXXXXXXXXXXXX">>,
public_key => ok,
...

thank you, this is the problem. If you manually change this to:

...
public_key => <<"XXXXXXXXXXXXXXX">>,
...

you should be good. Could you try? There's definitely a bug on our end though. Thank you for the report and extra information!

what is your Hex version? mix hex.info. Could you update with mix local.hex and see if it fixes it just in case?

I tried upating my config file to

{'$repos',#{<<"oban">> =>
                #{auth_key => <<"XXXXXXXXXXXXXXX">>,
                  public_key => <<"XXXXXXXXXXXXXX">>,
                  url => <<"https://getoban.pro/repo">>}}}.

And when running mix hex.repo list, I get:

** (MatchError) no match of right hand side value: []
    (hex 1.0.1) lib/mix/tasks/hex.repo.ex:207: Mix.Tasks.Hex.Repo.show_public_key/1
    (hex 1.0.1) lib/mix/tasks/hex.repo.ex:168: anonymous fn/1 in Mix.Tasks.Hex.Repo.list/0
    (elixir 1.13.2) lib/enum.ex:1597: anonymous fn/3 in Enum.map/2
    (stdlib 3.15.1) maps.erl:410: :maps.fold_1/3
    (elixir 1.13.2) lib/enum.ex:2408: Enum.map/2
    (hex 1.0.1) lib/mix/tasks/hex.repo.ex:164: Mix.Tasks.Hex.Repo.list/0
    (mix 1.13.2) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3
    (mix 1.13.2) lib/mix/cli.ex:84: Mix.CLI.run_task/2

Ran mix hex.info

Hex:    1.0.1
Elixir: 1.13.2
OTP:    24.0.3

Built with: Elixir 1.13.0 and OTP 22.3

mix local.hex doesn't seem to solve the issue

Thanks!

From what I can tell, it seems hex is not able ti fetch oban's public and store it as part of the config and instead stores ok

OK, thank you.

In the logs you mentioned before, this seems to be the culprit:

11:23:05.672 [notice] TLS :client: In state :certify at ssl_handshake.erl:1882 generated CLIENT ALERT: Fatal - Certificate Expired

Downloading public key failed
{:failed_connect, [{:to_address, {'getoban.pro', 443}}, {:inet, [:inet], {:tls_alert, {:certificate_expired, 'TLS client: In state certify at ssl_handshake.erl:1882 generated CLIENT ALERT: Fatal - Certificate Expired\n'}}}]}

it seems there was a problem downloading the public key and an incorrect one was written.

I think there were problems with certificates on some OTP versions. Could you try on newer OTP versions? The latest is 24.2.1.

@wojtekmach I see something weird when running mix hex.info

Ran mix hex.info

Hex:    1.0.1
Elixir: 1.13.2
OTP:    24.0.3

Built with: Elixir 1.13.0 and OTP 22.3

The 'Built with' part is not the same as my Elixir and OTP versions listed above, does that make sense?

that's not the issue. It just means that the .beam files that ship as part of your hex.ez archive have been compiled against those versions which is completely fine.

@wojtekmach I finally saw the problem, by mistake I added a package via brew that installed erlang as a dependency, and it was shadowing the version installed by asdf. closing and thanks for all your help, I really appreciate it

Awesome, glad it works now!