hex v0.13.0に上げたらクラッシュするようになった
hexのv0.13.0出たよアップデートしてね、というメッセージが出たので、v0.13.0に上げてみたところ、mixタスクを実行するとこんなエラーを吐いて止まるようになってしまった。
Could not start Hex. Try fetching a new version with "mix local.hex" or uninstalling it with "mix archive.uninstall hex.ez" 16:07:56.874 [info] Application hex exited: Hex.start(:normal, []) returned an error: shutdown: failed to start child: Hex.State ** (EXIT) an exception was raised: ** (MatchError) no match of right hand side value: {:error, {1, :erl_parse, ['syntax error before: ', []]}} (hex) lib/hex/config.ex:5: Hex.Config.read/0 (hex) lib/hex/state.ex:21: Hex.State.start_link/0 (stdlib) supervisor.erl:365: :supervisor.do_start_child/2 (stdlib) supervisor.erl:348: :supervisor.start_children/3 (stdlib) supervisor.erl:314: :supervisor.init_children/2 (stdlib) gen_server.erl:328: :gen_server.init_it/6 (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3 16:07:56.877 [info] Application inets exited: :stopped 16:07:56.877 [info] Application ssl exited: :stopped 16:07:56.878 [info] Application public_key exited: :stopped 16:07:56.878 [info] Application asn1 exited: :stopped 16:07:56.878 [info] Application crypto exited: :stopped ** (MatchError) no match of right hand side value: {:error, {:hex, {{:shutdown, {:failed_to_start_child, Hex.State, {:EXIT, {{:badmatch, {:error, {1, :erl_parse, ['syntax error before: ', []]}}}, [{Hex.Config, :read, 0, [file: 'lib/hex/config.ex', line: 5]}, {Hex.State, :start_link, 0, [file: 'lib/hex/state.ex', line: 21]}, {:supervisor, :do_start_child, 2, [file: 'supervisor.erl', line: 365]}, {:supervisor, :start_children, 3, [file: 'supervisor.erl', line: 348]}, {:supervisor, :init_children, 2, [file: 'supervisor.erl', line: 314]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 328]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]}}}}, {Hex, :start, [:normal, []]}}}} (hex) lib/hex.ex:5: Hex.start/0 (mix) lib/mix/hex.ex:53: Mix.Hex.start/0 (mix) lib/mix/dep/loader.ex:144: Mix.Dep.Loader.with_scm_and_app/4 (mix) lib/mix/dep/loader.ex:99: Mix.Dep.Loader.to_dep/3 (elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2 (mix) lib/mix/dep/loader.ex:299: Mix.Dep.Loader.mix_children/1 (mix) lib/mix/dep/loader.ex:18: Mix.Dep.Loader.children/0 (mix) lib/mix/dep/converger.ex:55: Mix.Dep.Converger.all/4
なんやらいろいろ出ているけれど、'syntax error before: '
と言っているのでどこかで何かの文法がおかしい様子。調べてみると、このエラーについてissueが立っていた。
エラーメッセージもっと改善しようよ、というのがissueの趣旨だけれど、古いhex.config
を置いていると出るエラーであるということがわかった。~/.hex/hex.config
があったので覗いてみると
[username: "Joe-noh", key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]
というものが書かれていて、このフォーマットが良くないっぽい。一度消したりなんだりして、以下のように書き直せばちゃんと動いた。
{username,<<"Joe-noh">>}. {key,<<"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">>}.
どうやらErlangのtermで書くように仕様が変わったみたいですな。https://github.com/hexpm/hex/issues/57 がこの件のissueのようだけど、2014年でほぼ2年前。随分と古い。ソースを辿ったら、v0.12.1のHex.Config.read/0
では以下のように、erlang termでなければelixir termとしてパースしていたところが、
case File.read(config_path()) do {:ok, binary} -> case decode_term(binary) do {:ok, term} -> term {:error, _} -> decode_elixir(binary) end {:error, _} -> [] end
v0.13.0のHex.Config.read/0
ではerlang termしか受け付けなくなったのでした。
case File.read(config_path()) do {:ok, binary} -> {:ok, term} = decode_term(binary) term {:error, _} -> [] end