From dfb3b4187c9223958f97ae31d31f4e82fb1ccf5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Meadows-J=C3=B6nsson?= Date: Fri, 31 May 2024 09:20:40 +0200 Subject: [PATCH] Add debugging --- lib/hex/http.ex | 15 +++++++++++---- lib/hex/registry/server.ex | 6 ++++-- lib/hex/remote_converger.ex | 8 ++++++++ lib/hex/scm.ex | 7 +++++-- lib/hex/state.ex | 5 ----- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/hex/http.ex b/lib/hex/http.ex index 40fb8f79..1f7e0a6b 100644 --- a/lib/hex/http.ex +++ b/lib/hex/http.ex @@ -17,6 +17,8 @@ defmodule Hex.HTTP do @impl :mix_hex_http def request(method, url, headers, body, opts \\ []) do + Hex.Shell.debug("Hex.HTTP.request(#{inspect(method)}, #{inspect(url)})") + headers = headers |> build_headers() @@ -36,7 +38,7 @@ defmodule Hex.HTTP do redirect(request, http_opts, @request_redirects, fn request, http_opts -> timeout(request, http_opts, timeout, fn request, http_opts -> :httpc.request(method, request, http_opts, opts, profile) - |> handle_response() + |> handle_response(method, url) end) end) end) @@ -176,14 +178,19 @@ defmodule Hex.HTTP do end end - defp handle_response({:ok, {{_version, code, _reason}, headers, body}}) do - headers = Map.new(headers, &decode_header/1) + defp handle_response({:ok, {{_version, code, _reason}, headers, body}}, method, url) do + Hex.Shell.debug("Hex.HTTP.request(#{inspect(method)}, #{inspect(url)}) => #{code}") + headers = Map.new(headers, &decode_header/1) handle_hex_message(headers["x-hex-message"]) {:ok, code, headers, unzip(body, headers)} end - defp handle_response({:error, term}) do + defp handle_response({:error, term}, method, url) do + Hex.Shell.debug( + "Hex.HTTP.request(#{inspect(method)}, #{inspect(url)}) => #{inspect(term, limit: :infinity, pretty: true)}" + ) + {:error, term} end diff --git a/lib/hex/registry/server.ex b/lib/hex/registry/server.ex index 55a9129f..60ff2484 100644 --- a/lib/hex/registry/server.ex +++ b/lib/hex/registry/server.ex @@ -135,7 +135,7 @@ defmodule Hex.Registry.Server do |> Enum.reject(&(&1 in state.fetched)) |> Enum.reject(&(&1 in state.pending)) - purge_repo_from_cache(packages, state) + purge_changed_repos_from_cache(packages, state) if Hex.State.fetch!(:offline) do prefetch_offline(packages, state) @@ -271,7 +271,7 @@ defmodule Hex.Registry.Server do :ok = :ets.tab2file(tid, String.to_charlist(path)) end - defp purge_repo_from_cache(packages, %{ets: ets}) do + defp purge_changed_repos_from_cache(packages, %{ets: ets}) do Enum.each(packages, fn {repo, _package} -> repo = repo || "hexpm" config = Hex.Repo.get_repo(repo) @@ -409,6 +409,8 @@ defmodule Hex.Registry.Server do "Failed to fetch record for #{Hex.Utils.package_name(repo, package)} from registry#{cached_message}" ) + Hex.Shell.debug("Error result: #{inspect(result, limit: :infinity, pretty: true)}") + if missing_status?(result) do Hex.Shell.error( "This could be because the package does not exist, it was spelled " <> diff --git a/lib/hex/remote_converger.ex b/lib/hex/remote_converger.ex index e8b2c2e5..e4849da9 100644 --- a/lib/hex/remote_converger.ex +++ b/lib/hex/remote_converger.ex @@ -32,9 +32,17 @@ defmodule Hex.RemoteConverger do # We need the old lock to get the children of Hex packages old_lock = Mix.Dep.Lock.read() + Hex.Shell.debug("Hex.RemoteConverger.converge()") + Hex.Shell.debug("deps: #{inspect(deps, limit: :infinity, pretty: true)}") + Hex.Shell.debug("lock: #{inspect(lock, limit: :infinity, pretty: true)}") + Hex.Shell.debug("old_lock: #{inspect(old_lock, limit: :infinity, pretty: true)}") + overridden = Hex.Mix.overridden_deps(deps) requests = Hex.Mix.deps_to_requests(deps) + Hex.Shell.debug("overridden: #{inspect(overridden, limit: :infinity, pretty: true)}") + Hex.Shell.debug("requests: #{inspect(requests, limit: :infinity, pretty: true)}") + [ Hex.Mix.packages_from_lock(lock), Hex.Mix.packages_from_lock(old_lock), diff --git a/lib/hex/scm.ex b/lib/hex/scm.ex index bd4febd3..7b98efa7 100644 --- a/lib/hex/scm.ex +++ b/lib/hex/scm.ex @@ -11,8 +11,11 @@ defmodule Hex.SCM do true end - def format(_opts) do - "Hex package" + def format(opts) do + case opts[:repo] do + "hexpm" -> "Hex package" + repo -> "Hex package (from #{repo})" + end end def format_lock(opts) do diff --git a/lib/hex/state.ex b/lib/hex/state.ex index 114af5ee..b626d61d 100644 --- a/lib/hex/state.ex +++ b/lib/hex/state.ex @@ -93,11 +93,6 @@ defmodule Hex.State do default: false, fun: {__MODULE__, :to_boolean} }, - resolve_verbose: %{ - env: ["HEX_RESOLVE_VERBOSE"], - default: false, - fun: {__MODULE__, :to_boolean} - }, repos_key: %{ env: ["HEX_REPOS_KEY"], config: [:repos_key]