lib/config.ex

defmodule SignificaUtils.Config do
  @moduledoc """
  Utility functions for config files.
  """

  @doc """
  Fetches a required environment variable, given its name.
  Not only the env needs to exist, but also it must not be empty.
  """
  def fetch_env(env_name) do
    System.get_env(env_name, "")
    |> case do
      "" ->
        raise "Environment variable '#{env_name}' must not be empty."

      variable ->
        variable
    end
  end
end