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

Incorrect warning for @derive Jason.Encoder #97

Closed
Ch4s3 opened this issue Jul 18, 2018 · 4 comments
Closed

Incorrect warning for @derive Jason.Encoder #97

Ch4s3 opened this issue Jul 18, 2018 · 4 comments

Comments

@Ch4s3
Copy link

Ch4s3 commented Jul 18, 2018

Environment

  • Elixir & Erlang versions (elixir --version):
    Erlang/OTP 21 [erts-10.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
    Elixir (1.6.6)

  • Operating system:
    macOS 10.13.5

  • Client (editor or IDE):
    vsCode 1.25.1

Basically an Ecto schema with a derive macro for Jason will show an incorrect error. Unfortunately, I missed grabbing the dev logs.

Code:

defmodule MyApp.MailData do
  @derive {Jason.Encoder,
           only: [:to, :subject, :sendgrid_template, :extra_data, :send_attempts, :priority]}
  schema "mail_data" do
    field(:to, :string)
    field(:subject, :string)
    field(:sendgrid_template, :string, default: "")
    field(:extra_data, :map, default: %{})
    field(:send_attempts, :integer, default: 0)
    field(:priority, :integer, default: 0)
  end
end

Error:

[Elixir]
** (BadArityError) #Function<1.119002335/3 in Jason.Codegen.encode_pair/2> with arity 3 called with 4 arguments ("to", "to", 0, [])
    lib/encode.ex:239: Jason.Encode.key/2
    lib/codegen.ex:126: Jason.Codegen.encode_pair/2
    (elixir) lib/enum.ex:1294: Enum."-map/2-lists^map/1-0-"/2
    lib/codegen.ex:48: Jason.Codegen.build_kv_iodata/2
    expanding macro: Jason.Encoder.Any.__deriving__/3
    lib/emails/mail_data.ex:21: MyApp.MailData (module)
    (elixir) lib/module.ex:516: Module.eval_quoted/4

The hot fix was uninstalling ElixirLS and reinstalling it, but @michalmuskala and I thought it might be worth filing an issue here. Thanks!

@JakeBecker
Copy link
Owner

This is most likely an unfortunate side effect of having Jason included in ElixirLS. If your project depends on a different version of it, it's a bit unpredictable which one ElixirLS will use in compilation.

I haven't thought of a good fix for this, but probably the simplest thing to mitigate it would be to keep up with Jason's minor releases so compilation is more likely to succeed.

@Ch4s3
Copy link
Author

Ch4s3 commented Jul 18, 2018

Interesting... I'll give this some thought.

@michalmuskala
Copy link

The only solution I could think of would be vendoring Jason inside the elixir-ls by copying the code and renaming modules. It's not ideal from the maintenance perspective, but should solve all such issues.

@JakeBecker
Copy link
Owner

This project has moved!

It's now being maintained by proactive volunteers from the Elixir community over at elixir-lsp/elixir-ls. Updates will continue to be published from that repo to the original VS Code extension, so no need to switch plugins if you're using VS Code.

To avoid inundating the new maintainers with issues, please verify that your issue persists with the latest version of the extension (which is published from the new repo) before re-filing your issue there.

Thanks for using ElixirLS!

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

3 participants