Skip to content

Commit

Permalink
Add base64 layer to erlang term passing
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerWitt committed Jan 15, 2025
1 parent 1d4236d commit 6b9d5cf
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
48 changes: 22 additions & 26 deletions hex/helpers/lib/check_update.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,26 @@ end

[dependency_name] = System.argv()

try do
case UpdateChecker.run(dependency_name) do
{:ok, version} ->
version = :erlang.term_to_binary({:ok, version})
IO.write(:stdio, version)

{:error, %Version.InvalidRequirementError{} = error} ->
result = :erlang.term_to_binary({:error, "Invalid requirement: #{error.requirement}"})
IO.write(:stdio, result)

{:error, %Mix.Error{} = error} ->
result = :erlang.term_to_binary({:error, "Dependency resolution failed: #{error.message}"})
IO.write(:stdio, result)

{:error, :dependency_resolution_timed_out} ->
# We do nothing here because Hex is already printing out a message in stdout
nil

{:error, error} ->
result = :erlang.term_to_binary({:error, "Unknown error in check_update: #{inspect(error)}"})
try do
IO.write(:stdio, result)
rescue e ->
IO.inspect("invalid chars: " <> inspect(error))
end
end
case UpdateChecker.run(dependency_name) do
{:ok, version} ->
version = :erlang.term_to_binary({:ok, version}) |> Base.encode64()
IO.write(:stdio, version)

{:error, %Version.InvalidRequirementError{} = error} ->
result = :erlang.term_to_binary({:error, "Invalid requirement: #{error.requirement}"}) |> Base.encode64()
IO.write(:stdio, result)

{:error, %Mix.Error{} = error} ->
result = :erlang.term_to_binary({:error, "Dependency resolution failed: #{error.message}"}) |> Base.encode64()
IO.write(:stdio, result)

{:error, :dependency_resolution_timed_out} ->
# We do nothing here because Hex is already printing out a message in stdout
nil

{:error, error} ->
result =
:erlang.term_to_binary({:error, "Unknown error in check_update: #{inspect(error)}"}) |> Base.encode64()

IO.write(:stdio, result)
end
1 change: 1 addition & 0 deletions hex/helpers/lib/do_update.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ lockfile_content =
"mix.lock"
|> File.read()
|> :erlang.term_to_binary()
|> Base.encode64()

IO.write(:stdio, lockfile_content)
2 changes: 1 addition & 1 deletion hex/helpers/lib/parse_deps.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ defmodule Parser do
end
end

dependencies = :erlang.term_to_binary({:ok, Parser.run()})
dependencies = :erlang.term_to_binary({:ok, Parser.run()}) |> Base.encode64()

IO.write(:stdio, dependencies)
2 changes: 1 addition & 1 deletion hex/helpers/lib/run.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule DependencyHelper do
if output =~ "No authenticated organization found" do
{:error, output}
else
{:ok, :erlang.binary_to_term(output)}
{:ok, :erlang.binary_to_term(Base.decode64!(output))}
end

{error, 1} ->
Expand Down

0 comments on commit 6b9d5cf

Please # to comment.