In a nutshell I have an error in production that I don’t have in development while using the same versions for all the software involved.
Environment
- Elixir version (elixir -v):
$ ./bin/tasks remote
Erlang/OTP 23 [erts-11.1.6] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1]
Interactive Elixir (1.11.3) - press Ctrl+C to exit (type h() ENTER for help)
- Domo version (mix deps | grep domo | head -1):
$ mix deps | grep domo | head -1
* domo 1.0.1 (Hex package) (mix)
- TypedStruct version (mix deps | grep typed_struct | head -1):
$ mix deps | grep typed_struct | head -1
* typed_struct 0.2.1 (Hex package) (mix)
I run it in development and in production with the docker image from the Phoenix releases docs:
https://hexdocs.pm/phoenix/releases.html#containers
Versions used to build the docker image:
ELIXIR_VERSION=1.11.3
ERLANG_OTP_VERSION=23.2.2
ALPINE_VERSION=3.12.1
Actual behavior
The error from a production release:
09:20:32.459 | error | module=gen_server function=error_info/7 line=943 | GenServer #PID<0.2551.0> terminating
app_1 | ** (UndefinedFunctionError) function Mix.Compilers.ApplicationTracer.trace/2 is undefined (module Mix.Compilers.ApplicationTracer is not available)
app_1 | Mix.Compilers.ApplicationTracer.trace({:alias_reference, [line: 45], NaiveDateTime}, #Macro.Env<aliases: [], context: nil, context_modules: [TypeIt.Progress], file: "/app/lib/type_it/lib/progress.ex", function: nil, functions: [{Kernel, [!=: 2, !==: 2, *: 2, ...]}], lexical_tracker: #PID<3.316.0>, line: 42, macro_aliases: [], macros: [{Domo, ...}, {...}], module: TypeIt.Progress, requires: [...], ...>)
app_1 | (elixir 1.11.3) src/elixir_env.erl:36: :elixir_env."-trace/2-lc$^0/1-0-"/3
app_1 | (elixir 1.11.3) src/elixir_env.erl:36: :elixir_env.trace/2
app_1 | (elixir 1.11.3) lib/macro.ex:1440: Macro.do_expand_once/2
app_1 | (elixir 1.11.3) lib/macro.ex:1610: Macro.expand_until/2
app_1 | (domo 1.0.1) lib/domo/type_spec_matchable/remote_type.ex:11: Domo.TypeSpecMatchable.RemoteType.expand/2
app_1 | (domo 1.0.1) lib/domo/type_contract.ex:642: Domo.TypeSpecMatchable.Any.match_spec?/3
app_1 | (tasks 0.1.0) lib/type_it/lib/progress.ex:42: TypeIt.Progress.TypeChecker.__field_error/1
The Typed Struct code:
defmodule TypeIt.Progress do
use Domo
@all_states %{
backlog: "Backlog",
todo: "Todo",
doing: "Doing",
pending: "Pending",
done: "Done",
archived: "Archived",
}
@states Map.keys(@all_states)
typedstruct do
field :state, :backlog | :todo | :doing | :pending | :done | :archived
field :title, String.t()
field :since, NaiveDateTime.t()
end
def default(), do: new_for!(:todo)
def next_state(:backlog), do: :todo
def next_state(:todo), do: :done
def next_state(:done), do: :todo
def new_for!(state), do: new!(state: state, title: @all_states[state], since: NaiveDateTime.utc_now())
def new_for!(state, since: since), do: new!(state: state, title: @all_states[state], since: since)
def new_for!(state, title: title), do: new!(state: state, title: title, since: NaiveDateTime.utc_now())
def states() do
@states
end
def all() do
@all_states
end
end
Expected behavior
In production is throwing the reported error that crashes the app, but in development it works ok.
Summary
Looking to this line in the logs:
Mix.Compilers.ApplicationTracer.trace({:alias_reference, [line: 45], NaiveDateTime},
It seems the error is related with using:
field :since, NaiveDateTime.t()
but I don’t get why I don’t have the same error in development, when using the same exact versions of Elixir, Phoenix, OTP, and Domo library
Any ideas?