Skip to content

Warn if no env set in config #60

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

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Config

config :logger, level: :critical
config :logger, level: :warning

config :phoenix_sync, mode: :disabled

Expand Down
38 changes: 31 additions & 7 deletions lib/phoenix/sync/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ defmodule Phoenix.Sync.Application do

@impl true
def start(_type, _args) do
case children() do
{:ok, children} ->
Supervisor.start_link(children, strategy: :one_for_one, name: Phoenix.Sync.Supervisor)
children =
case children() do
{:ok, children} ->
children

{:error, reason} ->
Logger.warning(reason)
Supervisor.start_link([], strategy: :one_for_one, name: Phoenix.Sync.Supervisor)
end
{:error, reason} ->
Logger.warning(reason)
[]
end

Supervisor.start_link(children, strategy: :one_for_one, name: Phoenix.Sync.Supervisor)
end

@doc false
Expand All @@ -41,6 +44,8 @@ defmodule Phoenix.Sync.Application do

@doc false
def children(opts) when is_list(opts) do
warn_missing_env(opts)

{adapter, env} = adapter_env(opts)

apply(adapter, :children, [env, opts])
Expand Down Expand Up @@ -73,4 +78,23 @@ defmodule Phoenix.Sync.Application do
:error -> {:error, "Missing required key #{inspect(key)}"}
end
end

defp warn_missing_env(config) do
if config[:mode] != :disabled && !config[:env] do
Logger.warning("""
No `env` specified for :phoenix_sync: defaulting to `:prod`.

Add the following to your config:

config :phoenix_sync,
env: config_env(),
# the rest of your config

In `:prod` mode, shapes are persisted between server restarts
which may cause problems in `:dev` or `:test` environments.
""")
end

config
end
end
17 changes: 16 additions & 1 deletion test/phoenix/sync/application_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Phoenix.Sync.ApplicationTest do

alias Phoenix.Sync.Application, as: App

import ExUnit.CaptureLog

Code.ensure_loaded!(Support.ConfigTestRepo)

defp validate_repo_connection_opts!(opts, overrides \\ []) do
Expand Down Expand Up @@ -78,7 +80,20 @@ defmodule Phoenix.Sync.ApplicationTest do
end

test "disabled mode" do
assert {:ok, []} = App.children(mode: :disabled)
refute capture_log(fn ->
assert {:ok, []} = App.children(mode: :disabled)
end) =~ ~r/No `env` specified for :phoenix_sync: defaulting to `:prod`/
end

test "warns if env not set" do
config = [
mode: :embedded,
repo: Support.ConfigTestRepo
]

assert capture_log(fn ->
assert {:ok, _} = App.children(config)
end) =~ ~r/No `env` specified for :phoenix_sync: defaulting to `:prod`/
end

test "embedded mode dev env" do
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy