Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swoosh crashes if phx.new.ecto does not get run with --no-mailer #5786

Open
adonig opened this issue Apr 21, 2024 · 1 comment
Open

Swoosh crashes if phx.new.ecto does not get run with --no-mailer #5786

adonig opened this issue Apr 21, 2024 · 1 comment

Comments

@adonig
Copy link

adonig commented Apr 21, 2024

Environment

  • Elixir version (elixir -v): 1.16.2
  • Phoenix version (mix deps): 1.7.12
  • Operating system: Fedora Linux 39 (Workstation Edition)

Actual behavior

$ mix phx.new.ecto domain
* creating domain/lib/domain/application.ex
* creating domain/lib/domain.ex
* creating domain/test/test_helper.exs
* creating domain/README.md
* creating domain/mix.exs
* creating domain/.gitignore
* creating domain/.formatter.exs
* creating domain/lib/domain/repo.ex
* creating domain/priv/repo/migrations/.formatter.exs
* creating domain/priv/repo/seeds.exs
* creating domain/test/support/data_case.ex

Fetch and install dependencies? [Yn] 
* running mix deps.get
* running mix deps.compile

We are almost there! The following steps are missing:

    $ cd domain

Then configure your database in config/dev.exs and run:

    $ mix ecto.create

You can run your app inside IEx (Interactive Elixir) as:

    $ iex -S mix

$ cd domain
$ mix ecto.create
Compiling 3 files (.ex)
Generated domain app
The database for Domain.Repo has been created
$ iex -S mix
10:40:25.899 [error] Could not find hackney dependency.

Please add :hackney to your dependencies:

    {:hackney, "~> 1.9"}

Or set your own Swoosh.ApiClient:

    config :swoosh, :api_client, MyAPIClient

10:40:25.907 [notice] Application swoosh exited: exited in: Swoosh.Application.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (RuntimeError) missing hackney dependency
            (swoosh 1.16.3) lib/swoosh/api_client/hackney.ex:26: Swoosh.ApiClient.Hackney.init/0
            (swoosh 1.16.3) lib/swoosh/api_client.ex:43: Swoosh.ApiClient.init/0
            (swoosh 1.16.3) lib/swoosh/application.ex:7: Swoosh.Application.start/2
            (kernel 9.2.2) application_master.erl:293: :application_master.start_it_old/4
10:40:25.932 [notice] Application finch exited: :stopped
10:40:25.932 [notice] Application nimble_options exited: :stopped
10:40:25.934 [notice] Application nimble_pool exited: :stopped
10:40:25.936 [notice] Application mint exited: :stopped
10:40:25.936 [notice] Application hpax exited: :stopped
10:40:25.936 [notice] Application castore exited: :stopped
10:40:25.936 [notice] Application mime exited: :stopped
10:40:25.936 [notice] Application xmerl exited: :stopped
10:40:25.938 [notice] Application ecto_sql exited: :stopped
10:40:25.938 [notice] Application postgrex exited: :stopped
10:40:25.939 [notice] Application db_connection exited: :stopped
10:40:25.940 [notice] Application ecto exited: :stopped
10:40:25.940 [notice] Application jason exited: :stopped
10:40:25.940 [notice] Application decimal exited: :stopped
10:40:25.941 [notice] Application telemetry exited: :stopped
10:40:25.941 [notice] Application eex exited: :stopped
10:40:25.941 [notice] Application phoenix_pubsub exited: :stopped
10:40:25.941 [notice] Application dns_cluster exited: :stopped
10:40:25.942 [notice] Application runtime_tools exited: :stopped
** (Mix) Could not start application swoosh: exited in: Swoosh.Application.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (RuntimeError) missing hackney dependency
            (swoosh 1.16.3) lib/swoosh/api_client/hackney.ex:26: Swoosh.ApiClient.Hackney.init/0
            (swoosh 1.16.3) lib/swoosh/api_client.ex:43: Swoosh.ApiClient.init/0
            (swoosh 1.16.3) lib/swoosh/application.ex:7: Swoosh.Application.start/2
            (kernel 9.2.2) application_master.erl:293: :application_master.start_it_old/4

Expected behavior

I believe phx.new.ecto should by default run with --no-mailer.

$ mix phx.new.ecto domain --no-mailer
* creating domain/lib/domain/application.ex
* creating domain/lib/domain.ex
* creating domain/test/test_helper.exs
* creating domain/README.md
* creating domain/mix.exs
* creating domain/.gitignore
* creating domain/.formatter.exs
* creating domain/lib/domain/repo.ex
* creating domain/priv/repo/migrations/.formatter.exs
* creating domain/priv/repo/seeds.exs
* creating domain/test/support/data_case.ex

Fetch and install dependencies? [Yn] 
* running mix deps.get
* running mix deps.compile

We are almost there! The following steps are missing:

    $ cd domain

Then configure your database in config/dev.exs and run:

    $ mix ecto.create

You can run your app inside IEx (Interactive Elixir) as:

    $ iex -S mix

$ cd domain/
$ mix ecto.create
Compiling 1 file (.ex)
Generated domain app
The database for Domain.Repo has already been created
$ iex -S mix
Erlang/OTP 26 [erts-14.2.3] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.16.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 
@adonig
Copy link
Author

adonig commented Apr 22, 2024

Okay, if we make --no-mailer the default, then it becomes impossible to create an Ecto project with Swoosh mailer files.

I believe Phoenix first needs boolean command line arguments that can be true and false, so it's possible to say:

$ mix phx.new.ecto domain --mailer

Now the default would create a new minimal Ecto project that just works as expected and at the same time it is still possible to add Swoosh if required.

EDIT: Nevermind, I realized it is already possible and it was just about setting the default value. See my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant