Skip to content

Commit

Permalink
Throw error when agent cannot be started (elixir-grpc#23)
Browse files Browse the repository at this point in the history
Update the agent function `start_agent_on_first_call/1` to continue to handle `already_started` and the normal start response, but now crashing on other input
Previously if there's an error when starting an agent, the error is
effectively silenced. I'm guessing this is to suppress `already_started`
"errors". Unfortunately this also suppress any error

With this change, `already_started` will be ignored, but any other error
will blow up, making it easy to see what went wrong. I considered
logging an error and continuing, but it's simpler to blow up, and feels
aligned with "let it crash"
  • Loading branch information
phunehehe authored Feb 2, 2024
1 parent 20d579d commit 07a295d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/grpc_reflection/service/agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ defmodule GrpcReflection.Service.Agent do

defp start_agent_on_first_call({name, services}) do
# lazy start agent on call
if match?({:ok, _}, GrpcReflection.DynamicSupervisor.start_child(name, services)) do
Logger.info("Started reflection agent #{name}")
case GrpcReflection.DynamicSupervisor.start_child(name, services) do
{:ok, _} -> Logger.info("Started reflection agent #{name}")
{:error, {:already_started, _}} -> :ok
end

name
Expand Down

0 comments on commit 07a295d

Please sign in to comment.