Skip to content
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

Production code is missing typespecs #3

Open
gorbak25 opened this issue Jan 9, 2020 · 4 comments
Open

Production code is missing typespecs #3

gorbak25 opened this issue Jan 9, 2020 · 4 comments

Comments

@gorbak25
Copy link

gorbak25 commented Jan 9, 2020

Expected behavior:
Forma works in self-contained releases.

Actual behavior:
Forma is working well in the dev environment. Forma isn't working at all in compiled releases as the typespecs the library is using are stripped away during compilation. Trying to use forma in production code results in the following error:

        ** (Protocol.UndefinedError) protocol Enumerable not implemented for nil of type Atom. This protocol is implemented for the following type(s): Ecto.Adapters.SQL.Stream, Postgrex.Stream, DBConnection.Stream, DBConnection.PrepareStream, GenEvent.Stream, HashSet, Date.Range, IO.Stream, Map, File.Stream, Stream, MapSet, Range, HashDict, List, Function
            (elixir) lib/enum.ex:1: Enumerable.impl_for!/1
            (elixir) lib/enum.ex:141: Enumerable.reduce/3
            (elixir) lib/enum.ex:3023: Enum.map/2
            (forma) lib/forma/typespecs.ex:6: Forma.Typespecs.compile/1
            (forma) lib/forma/types.ex:32: Forma.Types.compile/1
            (forma) lib/forma/types.ex:23: Forma.Types.handle_call/3
            (stdlib) gen_server.erl:661: :gen_server.try_handle_call/4
            (stdlib) gen_server.erl:690: :gen_server.handle_msg/6
    (elixir) lib/gen_server.ex:1009: GenServer.call/3
    (forma) lib/forma.ex:96: Forma.parse/3

@frekw
Copy link
Member

frekw commented Jan 9, 2020

Hi @grzegorz225!

That sounds weird, we're using it successfully across multiple production deployments (both using mix release as well as Distillery).

Could you provide a bit more information/example code to reproduce?

@gorbak25
Copy link
Author

gorbak25 commented Jan 14, 2020

@frekw Here is an minimal example which showcases the problem:
https://github.com/gorbak25/forma-bug
The demo tries to decode a simple json encoded payload each second and prints it to stdout, there is a test which tests decoding data using forma.
The tests pass and the app works correctly in both dev and prod environments - iex -S mix & MIX_ENV=prod iex -S mix

The app does not work as a compiled release:

  1. mix release
  2. _build/dev/rel/forma_demo/bin/forma_demo start

In the demo I'm getting the same error as in my other project.
I'm using Elixir 1.9.4 on OTP 22

@frekw
Copy link
Member

frekw commented Jan 14, 2020

@grzegorz225 interesting, I haven't seen that behaviour with mix release before.

Adding the following configuration keeps the typespec metadata around even when assembling a release:

  def project do
    [
      app: :forma_demo,
      version: "0.1.0",
      elixir: "~> 1.9",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      releases: [
        forma_demo: [strip_beams: false]
      ]
    ]
  end

@frekw
Copy link
Member

frekw commented Jan 14, 2020

See https://hexdocs.pm/mix/Mix.Tasks.Release.html#module-options for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants