sugar-framework / sugar

Modular web framework for Elixir
https://sugar-framework.github.io/
MIT License
430 stars 29 forks source link

`mix server` errors out with `(UndefinedFunctionError) undefined function: Foo.Router.run/0` as of 0.4.4 #65

Closed YellowApple closed 9 years ago

YellowApple commented 9 years ago

Full error:

DixonCider:my_website rnorthrup$ mix server
Compiled lib/yellowapple_site.ex
Compiled lib/yellowapple_site/controllers/main.ex
Compiled lib/yellowapple_site/router.ex
Generated yellowapple_site.app
** (UndefinedFunctionError) undefined function: YellowappleSite.Router.run/0
    (yellowapple_site) YellowappleSite.Router.run()
    lib/mix/tasks/server.ex:27: Mix.Tasks.Server.run/1
    (mix) lib/mix/cli.ex:55: Mix.CLI.run_task/2
    (elixir) lib/code.ex:316: Code.require_file/2

This code works fine with Sugar 0.4.3, which indicates (to me at least) that for some reason moving to HttpRouter broke things, and I've yet to figure out why, though my hunch is that there's some confusion about run's arity. Thoughts on this?

YellowApple commented 9 years ago

Content of lib/yellowapple_site/router.ex, for reference (doesn't deviate a whole lot from the defaults):

defmodule YellowappleSite.Router do
    use Sugar.Router
    plug Sugar.Plugs.HotCodeReload

    if Sugar.Config.get(:sugar, :show_debugger, false) do
        plug Plug.Debugger, otp_app: :your_project
    end

    plug Plug.Static, at: "/static", from: :yellowapple_site

    get "/", YellowappleSite.Controllers.Main, :index
end

And here's config/config.exs:

use Mix.Config

config :sugar, router: YellowappleSite.Router

config :sugar, YellowappleSite.Router, https_only: false, https: false, http: [
    port: 4000
]
slogsdon commented 9 years ago

@YellowApple I'd have to say that the switch to HttpRouter is the cause, but I'm not sure yet why. The run function should be available thanks to the definition in the __before_compile__/1 macro. I'll dig around and try to figure out what's up.

YellowApple commented 9 years ago

That's what I figure, too; the run function definition in that macro didn't change at all during the switch to HttpRouter (at least according to the commit diffs), so it should work at least as well as it did before (at least at that point).

For what it's worth, the dirty hack of copying run's definition into lib/yellowapple_site/router.ex makes everything work correctly, even with HttpRouter. So it's definitely something going on with that macro, but why it would suddenly be a problem now is an unanswered question.

YellowApple commented 9 years ago

Aaaaand ficks'd.

Turns out we just needed to actually use that macro definition in the __using__ macro; shoving @before_compile Sugar.Router after the use HttpRouter, ... clause fixed everything (at least in my simple hello-world-style app).

slogsdon commented 9 years ago

Nice job! I was driving to work and remembered that the @before_compile line wasn't there anymore, so I'm glad you figured it out as well. :thumbsup: