Skip to content

Commit

Permalink
Add debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmj committed May 31, 2024
1 parent c561e70 commit dfb3b41
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
15 changes: 11 additions & 4 deletions lib/hex/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions lib/hex/registry/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 " <>
Expand Down
8 changes: 8 additions & 0 deletions lib/hex/remote_converger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 5 additions & 2 deletions lib/hex/scm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions lib/hex/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit dfb3b41

Please sign in to comment.