elixir-inspector / ua_inspector

User agent parser library
Apache License 2.0
127 stars 23 forks source link

(UndefinedFunctionError) function UAInspector.Supervisor.start_link/0 is undefined #9

Closed wulymammoth closed 7 years ago

wulymammoth commented 7 years ago

Having an issue just test-driving this lib in an a Phoenix app. Each time I try to start the Phoenix server or start an IEx shell, I receive the below error.

I'm not sure what I'm missing here. I've tried adding :ua_inspector to :extra_applications in the Mixfile and I have added the UAInspector.Supervisor spec to a the list of children in the Phoenix application which causes the below, because it doesn't seem to be able to find the module and/or function. I looked through the repo and I see that the module exists. I've been wracking my brain around this for about an hour and a half to no avail. Any help is greatly appreciated.

Elixir 1.5.1 Phoenix 1.3.1

=INFO REPORT==== 27-Aug-2017::22:00:21 ===
    application: logger
    exited: stopped
    type: temporary
** (Mix) Could not start application therealreal: TheRealReal.Application.start(:normal, []) returned an error: shutdown: failed to start child: UAInspector.Supervisor
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function UAInspector.Supervisor.start_link/0 is undefined (module UAInspector.Supervisor is not available)
            UAInspector.Supervisor.start_link()
            (stdlib) supervisor.erl:365: :supervisor.do_start_child/2
            (stdlib) supervisor.erl:348: :supervisor.start_children/3
            (stdlib) supervisor.erl:314: :supervisor.init_children/2
            (stdlib) gen_server.erl:365: :gen_server.init_it/2
            (stdlib) gen_server.erl:333: :gen_server.init_it/6
            (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
mneudert commented 7 years ago

Could it be that you are using the current release version from Hex while trying to follow the README on GitHub?

There have been some yet to be released changes to the startup process in https://github.com/elixytics/ua_inspector/commit/4a04e5e01d097336ee9579994e08db72afe3ae4a you are probably getting confused by.

Just adding the application to the Mixfile should be enough.

wulymammoth commented 7 years ago

@mneudert I've removed the following from the list of children and it works and I'm able to access module functions and kick off the app or shell. I'm just unsure about how UAInspector will be supervised without it.

supervisor(UAInspector.Supervisor, [])
mneudert commented 7 years ago

It is supervised via it's own application. Manually adding the supervisor is only useful if you do explicitly not want to start the application itself, perhaps because of some special startup code you want to run beforehand.

But to do that you would also need to move :ua_inspector from :extra_applications to :included_applications as the first one automatically starts the application (and the supervision there) while the latter one only makes sure the code is available in an application release. (Only available on GitHub, not yet via Hex!)

If you are interested in how the supervision tree of your application looks like you can run :observer.start() (erlang doc) from a connected iex session (iex -S mix phx.server should suffice). Whether that works depends on your environment but if it does it might help a lot :)