goth icon indicating copy to clipboard operation
goth copied to clipboard

disable: true not working in v1.3.0

Open kandaiiskandar opened this issue 2 years ago • 1 comments

I have added Goth to my supervision tree and set config :goth, disabled: true

When i start the server, It throws an error. [error] GenServer {Goth.Registry, Academy.Goth} terminating ** (CaseClauseError) no case clause matching: :error (goth 1.3.0) lib/goth/token.ex:231: Goth.Token.request/1 (goth 1.3.0) lib/goth.ex:194: Goth.prefetch/1 (goth 1.3.0) lib/goth.ex:187: Goth.handle_continue/2 (stdlib 3.17) gen_server.erl:695: :gen_server.try_dispatch/4 (stdlib 3.17) gen_server.erl:437: :gen_server.loop/7 (stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3 Last message: {:continue, :async_prefetch}

kandaiiskandar avatar Aug 11 '22 12:08 kandaiiskandar

A PR that raises a better error message would be very appreciated. Ideally we'd raise the same error as before:

iex(1)> Mix.install [{:goth, "~> 1.2.0"}]
:ok
iex(2)>
15:57:07.917 [notice] Application goth exited: Goth.start(:normal, []) returned an error: shutdown: failed to start child: Goth.Config
    ** (EXIT) an exception was raised:
        ** (RuntimeError)  Failed to retrieve project data from GCE internal metadata service.
                   Either you haven't configured your GCP credentials, you aren't running on GCE, or both.
                   Please see README.md for instructions on configuring your credentials.
            (goth 1.2.0) lib/goth/config.ex:182: Goth.Config.determine_project_id/2
            (goth 1.2.0) lib/goth/config.ex:73: anonymous fn/2 in Goth.Config.load_and_init/1
            (elixir 1.15.0-dev) lib/enum.ex:1662: anonymous fn/3 in Enum.map/2
            (stdlib 4.0.1) maps.erl:411: :maps.fold_1/3
            (elixir 1.15.0-dev) lib/enum.ex:2480: Enum.map/2
            (goth 1.2.0) lib/goth/config.ex:71: Goth.Config.load_and_init/1
            (stdlib 4.0.1) gen_server.erl:848: :gen_server.init_it/2
            (stdlib 4.0.1) gen_server.erl:811: :gen_server.init_it/6

wojtekmach avatar Aug 11 '22 13:08 wojtekmach

Thank you @wojtekmach for looking into this. I'm seeing the same. Is disabled: true supposed to be working during test in 1.3.1? Your response suggests that you'd like to add a better error message, but I think this should not result in an error at all.

Alternatively, what's the suggested way of handling goth during testing? Check if the env is test and not add it to the supervisor tree?

nwittstruck avatar Oct 02 '22 17:10 nwittstruck

I have the same query really, since goth will try to run with no configuration (as we only want to use goth in prod and not in development or testing - apart from in the integration testing cases we may have). For now I will adopt the approach that @nwittstruck suggests as a brute force workaround.

dokie avatar Oct 13 '22 13:10 dokie

Alternatively, what's the suggested way of handling goth during testing? Check if the env is test and not add it to the supervisor tree?

Yes, exactly.

I'm going to close but of course feel free to keep discussing.

wojtekmach avatar Oct 13 '22 14:10 wojtekmach