Skip to content

Instantly share code, notes, and snippets.

@KronicDeth
Created May 22, 2017 20:39
Show Gist options
  • Save KronicDeth/d7cfec38d4930585ffbbf970967c2277 to your computer and use it in GitHub Desktop.
Save KronicDeth/d7cfec38d4930585ffbbf970967c2277 to your computer and use it in GitHub Desktop.
HowTo make deprecation warnings in Elixir

TIL how to make deprecation warnings:

Compiling 2 files (.ex)
warning: `Retort.Resources.timeout/2` is deprecated; call `Retort.Resources.Timeout.get_or_default/2` instead.
  lib/retort/resources.ex:197: Retort.Resources.timeout/2

Replace function

  @spec timeout(module) :: Keyword.t | timeout
  defp timeout(module) do
    :retort
    |> Application.get_env(module, [])
    |> Keyword.get(:timeout, @default_timeout)
  end

With (undocumented) macro that replaces the call

  @doc false
  @spec timeout(module, Retort.Resources.Timeout.function_name) :: timeout
  defmacro timeout(module, function_name) do
    IO.warn "`Retort.Resources.timeout/2` is deprecated; call `Retort.Resources.Timeout.get_or_default/2` instead.",
            Macro.Env.stacktrace(__ENV__)

    quote do
      Retort.Resources.Timeout.get_or_default(unquote(module), unquote(function_name))
    end
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment