phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.42k stars 2.87k forks source link

`mix phx.new` isn't working anymore..? #5807

Closed lucavenir closed 6 months ago

lucavenir commented 6 months ago

Environment

Actual behavior

I tried and experimented with phoenix in the last month; so I wanted to expand via a first "more serious" project. But now I'm not able to get Up And Running anymore 😢 Or at least not without encountering an error.

Up And Running says we should run these:

mix phx.new hello
cd hello
mix ecto.create
mix phx.server

To correctly start the server. Which works.

But whenever I hit http://localhost:4000/, the server reports this error

[info] GET /
[debug] Processing with HelloWeb.PageController.home/2
  Parameters: %{}
  Pipelines: [:browser]
[debug] Plug.Session could not verify incoming session cookie. This may happen when the session settings change or a stale cookie is sent.
[info] Sent 200 in 125ms
[error] GenServer #PID<0.681.0> terminating
** (Protocol.UndefinedError) protocol String.Chars not implemented for {Hello.Repo, :dynamic_repo} of type Tuple. This protocol is implemented for the following type(s): Atom, BitString, Date, DateTime, Decimal, Float, Integer, List, NaiveDateTime, Phoenix.LiveComponent.CID, Postgrex.Copy, Postgrex.Query, Time, URI, Version, Version.Requirement
    (elixir 1.16.2) lib/string/chars.ex:3: String.Chars.impl_for!/1
    (elixir 1.16.2) lib/string/chars.ex:22: String.Chars.to_string/1
    (bandit 1.5.1) lib/bandit/http1/handler.ex:37: anonymous fn/1 in Bandit.HTTP1.Handler.clear_process_dict/0
    (elixir 1.16.2) lib/enum.ex:987: Enum."-each/2-lists^foreach/1-0-"/2
    (bandit 1.5.1) lib/bandit/http1/handler.ex:26: Bandit.HTTP1.Handler.maybe_keepalive/2
    (bandit 1.5.1) lib/bandit/delegating_handler.ex:18: Bandit.DelegatingHandler.handle_data/3
    (bandit 1.5.1) /home/venir/Documents/venir.dev/letmego/hello/deps/thousand_island/lib/thousand_island/handler.ex:411: Bandit.DelegatingHandler.handle_continue/2
    (stdlib 5.2.1) gen_server.erl:1085: :gen_server.try_handle_continue/3
    (stdlib 5.2.1) gen_server.erl:995: :gen_server.loop/7
    (stdlib 5.2.1) proc_lib.erl:241: :proc_lib.init_p_do_apply/3
Last message: {:continue, :handle_connection}
State: {%ThousandIsland.Socket{socket: #Port<0.23>, transport_module: ThousandIsland.Transports.TCP, read_timeout: 60000, silent_terminate_on_error: false, span: %ThousandIsland.Telemetry{span_name: :connection, telemetry_span_context: #Reference<0.2608432043.774111238.62414>, start_time: -576460741391933468, start_metadata: %{remote_port: 48622, remote_address: {127, 0, 0, 1}, telemetry_span_context: #Reference<0.2608432043.774111238.62414>, parent_telemetry_span_context: #Reference<0.2608432043.774111237.62749>}}}, %{opts: %{http: [], websocket: [], http_1: [], http_2: []}, plug: {Phoenix.Endpoint.SyncCodeReloadPlug, {HelloWeb.Endpoint, []}}, handler_module: Bandit.InitialHandler, http_1_enabled: true, http_2_enabled: true}}

Expected behavior

No [error] should ever appear on a GET / request... Especially after following the simplest up-and-running guide on the web 😄

The error points towards ThousandIsland and Bandit, so I'm not sure how to solve this problem.

chrismccord commented 6 months ago

This looks like an issue that was introduced with Bandit 1.5.1. In the meantime, you can set bandit was {:bandit, "1.5.0"}. Thanks for the report! We'll coordinate on the bandit side to get this fixed up.

lucavenir commented 6 months ago

Thank you - I did not realize there was a bandit upgrade. Could I ask how I could have noticed this one by myself and prevented the "spam" in here?

lucavenir commented 6 months ago

Hold on, my mix.exs file contains the following dependencies:

defmodule Hello.MixProject do
  use Mix.Project

  def project do
    [
      app: :hello,
      version: "0.1.0",
      elixir: "~> 1.14",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  # Configuration for the OTP application.
  #
  # Type `mix help compile.app` for more information.
  def application do
    [
      mod: {Hello.Application, []},
      extra_applications: [:logger, :runtime_tools]
    ]
  end

  # Specifies which paths to compile per environment.
  defp elixirc_paths(:test), do: ["lib", "test/support"]
  defp elixirc_paths(_), do: ["lib"]

  # Specifies your project dependencies.
  #
  # Type `mix help deps` for examples and options.
  defp deps do
    [
      {:phoenix, "~> 1.7.12"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.10"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 4.0"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_view, "~> 0.20.2"},
      {:floki, ">= 0.30.0", only: :test},
      {:phoenix_live_dashboard, "~> 0.8.3"},
      {:esbuild, "~> 0.8", runtime: Mix.env() == :dev},
      {:tailwind, "~> 0.2", runtime: Mix.env() == :dev},
      {:heroicons,
       github: "tailwindlabs/heroicons",
       tag: "v2.1.1",
       sparse: "optimized",
       app: false,
       compile: false,
       depth: 1},
      {:swoosh, "~> 1.5"},
      {:finch, "~> 0.13"},
      {:telemetry_metrics, "~> 1.0"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.20"},
      {:jason, "~> 1.2"},
      {:dns_cluster, "~> 0.1.1"},
      {:bandit, "~> 1.2"}  # !!! 1.2, not 1.5.1
    ]
  end

  # Aliases are shortcuts or tasks specific to the current project.
  # For example, to install project dependencies and perform other setup tasks, run:
  #
  #     $ mix setup
  #
  # See the documentation for `Mix` for more info on aliases.
  defp aliases do
    [
      setup: ["deps.get", "ecto.setup", "assets.setup", "assets.build"],
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"],
      "assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
      "assets.build": ["tailwind hello", "esbuild hello"],
      "assets.deploy": [
        "tailwind hello --minify",
        "esbuild hello --minify",
        "phx.digest"
      ]
    ]
  end
end

what should I put instead of 1.2, then?

chrismccord commented 6 months ago

We generate a mix.exs reference for you like {:bandit, "~> 1.5"}, so it will pick up the latest compatible release. In this case, it picked up a bad release. So nothing you could look out for or stay on top of. Just a simple bug which will be fixed up shortly :)

chrismccord commented 6 months ago

You specifically want to lock it at {:bandit, "1.5.0"}

lucavenir commented 6 months ago

Thank you a ton for your patience 🙏🏼 Unluckily, I cannot help further. Have a great day!

mtrudel commented 6 months ago

Bandit 1.5.2 released with a fix for this

mtrudel commented 6 months ago

@lucavenir I'd just released 1.5.1 a few hours ago so you were among the few unlucky first users. Sorry for the trouble!

lucavenir commented 6 months ago

You guys are incredible!

Sorry for the trouble!

Don't you dare! So thank you for answering this quickly! Have a great day!