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

Error when configuring like examples #128

Open
kyleboe opened this issue Sep 11, 2021 · 0 comments
Open

Error when configuring like examples #128

kyleboe opened this issue Sep 11, 2021 · 0 comments

Comments

@kyleboe
Copy link

kyleboe commented Sep 11, 2021

Elixir 1.12.3
Phoenix 1.5.12
Vapor 0.10.0

I haven't dug into why this error is now happening but when configuring like the example here:

defmodule VaporExample.Config do
  use Vapor.Planner

  dotenv()

  config :db, env([
    {:url, "DB_URL"},
    {:name, "DB_NAME"},
    {:pool_size, "DB_POOL_SIZE", default: 10, map: &String.to_integer/1},
  ])

  config :web, env([
    {:port, "PORT", map: &String.to_integer/1},
  ])

  config :kafka, VaporExample.Kafka
end

defmodule VaporExample.Application do
  use Application

  def start(_type, _args) do
    config = Vapor.load!(VaporExample.Config)

    children = [
       {VaporExampleWeb.Endpoint, config.web},
       {VaporExample.Repo, config.db},
       {VaporExample.Kafka, config.kafka},
    ]

    opts = [strategy: :one_for_one, name: VaporExample.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

I get the following error:

(FunctionClauseError) no function clause matching in Keyword.get/3

Turns out, the issue is resolved by changing the children configuration lines to first convert to a Keyword List instead of a Map like so:

{VaporExampleWeb.Endpoint, Map.to_list(config.web)},
{VaporExample.Repo, Map.to_list(config.db)},

A solution might be adding a function like Vapor.load_list!() to load the config as a Keyword List. Thoughts?

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