cpjk / canary

:hatching_chick: Elixir authorization and resource-loading library for Plug applications.
MIT License
474 stars 51 forks source link

Error when building for prod #56

Closed snewcomer closed 7 years ago

snewcomer commented 7 years ago

After deploying to a server, I am getting:

Canada.Can.can?/3 is undefined (module Canada.Can is not available)
Canada.Can.can?(%App.User{...}, :update, %App.Location{...})

Abilities file:

defmodule Canary.Abilities do

  defimpl Canada.Can, for: User do

    def can?(%User{} = user, :update, %Location{}), do: LocationPolicy.update?(user)

Any thoughts on why this is failing after building and deploying (using distillery) to a server, but working locally? Not much to go on, but if you have encountered something similar, it would be great to hear! Otherwise will close this issue.

snewcomer commented 7 years ago

So what is interesting is building for production, I see this stack trace (_authorize_resource). This is pre this commit. However, locally I have the correct canary code in my deps folder. I am using {:canary, github: "cpjk/canary"},. Any thoughts on why this is occurring when building and deploying to prod?

screen shot 2017-03-28 at 5 53 01 pm
cpjk commented 7 years ago

If you're using Canary in production, I would recommend using the version on hex, rather than github, as it is more stable.

As for the error, would you mind posting the whole stack trace? https://github.com/cpjk/canary/blob/master/lib/canary/plugs.ex#L207 doesn't look like it's doing much.

snewcomer commented 7 years ago

@cpjk Definitely. Will do. I actually just realized it might be an old cached version (before the above commit ref) on my build server (rather than an unpublished pkg or something like that, if that is even possible)

snewcomer commented 7 years ago

@cpjk Sorry terrible theories on my part :). So here is the undefined function from my error log. Expands to Canada.Can.can?(%MyApp.User{...}, :update, %MyApp.Resource{...}). So it has an arity of 3, I'm passing 3 arguments, etc. It works locally but not after building and deploying (w/ distillery and edeliver) to a server. Any thoughts on other debugging techniques to figure out this problem?

Elixir 1.4.2 Erlang 19.2

screen shot 2017-03-29 at 10 41 02 am screen shot 2017-03-29 at 10 50 29 am

Then when jumping into iex -S mix locally:

screen shot 2017-03-29 at 11 18 29 am

but on my server bin/myapp console or bin/myapp remote_console while it is running:

screen shot 2017-03-29 at 11 20 47 am
snewcomer commented 7 years ago

Turns out I had to add canada to extra_applications in my mix file.