aaronrenner / phx_gen_auth

An authentication system generator for Phoenix 1.5 applications.
772 stars 55 forks source link

Mix.Tasks.Phx.Gen.Context.build/2 is undefined #80

Closed mcelaney closed 4 years ago

mcelaney commented 4 years ago

Elixir 1.10.4 Erlang/OTP 23 Phoenix 1.5.4

Installed Phoenix, credo, and dialyxir

Added {:phx_gen_auth, "~> 0.5", only: [:dev], runtime: false} to mix.exs... then ran in to the following exception.

$ mix phx.gen.auth Accounts User users
** (UndefinedFunctionError) function Mix.Tasks.Phx.Gen.Context.build/2 is undefined (module Mix.Tasks.Phx.Gen.Context is not available)
    Mix.Tasks.Phx.Gen.Context.build(["Accounts", "User", "users"], Mix.Tasks.Phx.Gen.Auth)
    lib/mix/tasks/phx.gen.auth.ex:98: Mix.Tasks.Phx.Gen.Auth.run/1
    (mix 1.10.4) lib/mix/task.ex:330: Mix.Task.run_task/3
    (mix 1.10.4) lib/mix/cli.ex:82: Mix.CLI.run_task/2

mix phx.gen.context Accounts User users name:string works fine... so I'm not sure what's going on here...

mcelaney commented 4 years ago

Dropping to Elixir 1.10.2 to run the task and then back to elixir 1.10.4 got me past it...

aaronrenner commented 4 years ago

@mcelaney I wasn't able to recreate the issue locally, but I wonder if somehow a version of phoenix <1.5.2 has gotten into your path. This PR (https://github.com/phoenixframework/phoenix/pull/3737) created the build/2 function your system appears to be missing and was released in phoenix 1.5.2. I'd be curious what the output of mix archives is when using your elixir 1.10.4 and 1.10.2 installs.

I hope this helps and it's great to hear you were able to get past it.

mcelaney commented 4 years ago

Ah that let me see the problem... in 1.10.4 I had the phx_gen_auth-0.5.0 archive which was causing issues. I had loaded it while trying to run the tests on the library... was thinking of sending a PRs to add @spec statements and gettext for all the strings (which I ended up unfortunately bailing on due to time... but if there is interest I can circle back)

Removing that clears the issue.

aaronrenner commented 4 years ago

Glad to hear this works! phx_gen_auth isn't meant to be installed as an archive, so I'm not sure if that caused the issue. I'm going to close this issue, since it sounds like its fixed.

Regarding the specs and gettext PRs, phx_gen_auth needs to stay consistent with the rest of the phoenix generators. The generators don't use specs, so we won't be adding them here either. I'm less familiar with the thoughts behind adding gettext, but I noticed phx.gen.html doesn't use it. I'd suggest opening an issue in phoenix to see if they want to use gettext more in the generators, and if so, PRs would be welcome in both projects.

mcelaney commented 4 years ago

Yea - that's part of why I decided not to take the time. I'll probably maintain a fork that has it - takes a couple hours to lock it all down if you're a dialyxir enthusiast who does a lot of localized projects ;)