Skip to content

Error when configuring like examples #128

Description

@kyleboe

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions