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 5190079
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
18 changes: 15 additions & 3 deletions lib/hex/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ defmodule Hex.HTTP do

@impl :mix_hex_http
def request(method, url, headers, body, opts \\ []) do
if Mix.debug?() do
Hex.Shell.debug("Hex.HTTP.request(#{inspect(method)}, #{inspect(url)})")
end

headers =
headers
|> build_headers()
Expand All @@ -36,7 +40,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 +180,22 @@ defmodule Hex.HTTP do
end
end

defp handle_response({:ok, {{_version, code, _reason}, headers, body}}) do
defp handle_response({:ok, {{_version, code, _reason}, headers, body}}, method, url) do
if Mix.debug?() do
Hex.Shell.debug("Hex.HTTP.request(#{inspect(method)}, #{inspect(url)}) => #{code}")
end

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
if Mix.debug?() do
Hex.Shell.debug("Hex.HTTP.request(#{inspect(method)}, #{inspect(url)}) => #{inspect(term)}")
end

{:error, term}
end

Expand Down
8 changes: 6 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,10 @@ defmodule Hex.Registry.Server do
"Failed to fetch record for #{Hex.Utils.package_name(repo, package)} from registry#{cached_message}"
)

if Mix.debug?() do
Hex.Shell.error("Error result: #{inspect(result)}")
end

if missing_status?(result) do
Hex.Shell.error(
"This could be because the package does not exist, it was spelled " <>
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

0 comments on commit 5190079

Please sign in to comment.