elixir-maru / maru

Elixir RESTful Framework
https://maru.readme.io
BSD 3-Clause "New" or "Revised" License
1.32k stars 84 forks source link

config :maru, test: false #70

Closed nonotest closed 7 years ago

nonotest commented 7 years ago

Hello,

(not an elixir dev sorry if incorrect)

With the latest commits and the introduction of test_mode/0 it seems that releases built by exrm/distillery fail without forcing the test mode to false.

case Application.get_env(:maru, :test) do
 +      true  -> true
 +      false -> false
 +      nil   -> Mix.env == :test

Attempts to run Mix.env but it doesn't exists with release mode so crashes. If this is true maybe we could document it better?

falood commented 7 years ago

Hi @nonotest , I test it locally with distillery and no exception raised, could you please show me more details about the error?

brandonparsons commented 7 years ago

Hello @falood . Note the following in the Distillery documentation:

... your application should never use anything from the Mix.* namespace

- With releases, at runtime there is no longer any Mix project information, as your application is indistinguishable from any other Erlang application. This means your application should never use anything from the Mix.* namespace.

Given that, the error is reasonably self-explanatory:

2017-08-08 12:21:00.771 [info] Application maru exited: exited in: Maru.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function Mix.env/0 is undefined (module Mix is not available)
            Mix.env()
            (maru) lib/maru.ex:35: Maru.test_mode?/0
            (maru) lib/maru/supervisor.ex:7: Maru.Supervisor.start_link/0
            (kernel) application_master.erl:273: :application_master.start_it_old/4

The changes introduced in my pull request make Maru work with Distillery in production.

nonotest commented 7 years ago

yep - @brandonparsons 's description is exactly what happens.

falood commented 7 years ago

Thank you very much @brandonparsons @nonotest maru 0.12.2 released with this issue fixed.