Warning: you are implementing a protocol for ... but said module is not available

@zachdaniel I started getting this again with some other embedded resources I have, for example:

This embedded resource in lib/core/marketplace/messages/notification/types/normal.ex:

defmodule Core.Marketplace.Messages.Notification.Types.Normal do
  @moduledoc false

  use Ash.Resource,
    data_layer: :embedded

  attributes do
    attribute :message, :string, allow_nil?: false, public?: true
  end
end

With this defimpl in lib/core/marketplace/messages/notification/types/normal/persistent.ex:

defimpl CoreWeb.Components.Notification.Persistent.Protocol,
  for: Core.Marketplace.Messages.Notification.Types.Normal do
  alias CoreWeb.Components.Notification.Persistent.Normal

  def to_notification(data, full_notification) do
    %{type: type} = full_notification
    %{message: message} = data

    opts = Flashy.Normal.Options.new(dismissible?: true)

    Normal.new(type, message, opts)
  end
end

Will generate the following warning:

    warning: you are implementing a protocol for Core.Marketplace.Messages.Notification.Types.Normal but said module is not available. Make sure the module name is correct. If Core.Marketplace.Messages.Notification.Types.Normal is an optional dependency, please wrap the protocol implementation in a Code.ensure_loaded?(Core.Marketplace.Messages.Notification.Types.Normal) check
    │
  1 │ defimpl CoreWeb.Components.Notification.Persistent.Protocol,
    │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ lib/core/marketplace/messages/notification/types/normal/persistent.ex:1: (file

I’m using spark 2.3.14

Another thing that I noticed @zachdaniel is that, if I add the defimpl for the resource in the same module file or inside the module itself and then I change any LV file in my project, it always recompiles the resource.

I’m not sure why a LV page would trigger that as the page itself doesn’t have any directly link to the resource, but as soon as I remove the protocol implementation, it stops recompiling…

Not sure if this is an Elixir or Ash issue though, any ideas or suggestions of what I can do to give more information?

Regarding the warnings, @zachdaniel I found the issue, basically this commit in spark 2.3.11:

Reverts the commit that fixed the issue in 2.3.7:

And reason for this to be reverted? And if so, any idea on how to fix the warnings without it?

2 Likes

@sezaru sorry I haven’t had a chance to look at this until now sorry. It’s pretty strange, but ultimately it really doesn’t make sense to me that the change you’re linking to would solve this problem. I forget if this was an issue reported separately with a repo or not, but I did have to remove that check and honestly I don’t remember why :cry:

As for recompilation, perhaps a tip from this recent article could help? Blog

Its hard to think about these things in the abstract so maybe lets dig up whatever repro was from before and I can take a look again?

I do have a project to trigger it, it was in the original post

Here is the project

We can easily test this by changing the mix.exs deps to:

      {:ash, "~> 3.9"},
      {:spark, "== 2.3.11"},

And then run MIX_ENV=test mix compile --force --profile time

This will generate the app without any warnings:

==> core
Compiling 6 files (.ex)
[profile]     23ms compiling +      0ms waiting while compiling lib/core/application.ex
[profile]     62ms compiling +      0ms waiting while compiling test/support/factory/builder.ex
[profile]    375ms compiling +      0ms waiting while compiling lib/core/marketplace/chat.ex
[profile]   1991ms compiling +      0ms waiting while compiling lib/core/marketplace/chat/attachment.ex
[profile]    998ms compiling +   1820ms waiting for module Core.Marketplace.Chat.Attachment while compiling lib/core/marketplace/chat/property_message.ex
[profile]     66ms compiling +   2687ms waiting for module Core.Marketplace.Chat.PropertyMessage while compiling test/support/factory/marketplace/chat/property_message.ex
[profile] Finished cycle resolution in 0ms
[profile] Finished compilation cycle of 9 modules in 2852ms
[profile] Finished group pass check of 9 modules in 179ms
Generated core app

But, if we update the spark version to 2.3.12 or newer:

      {:ash, "~> 3.9"},
      {:spark, "== 2.3.12"},

And run the same command MIX_ENV=test mix compile --force --profile time

Now we will see the warning being generated:

==> core
Compiling 6 files (.ex)
[profile]     38ms compiling +      0ms waiting while compiling lib/core/application.ex
[profile]     79ms compiling +      0ms waiting while compiling test/support/factory/builder.ex
[profile]    420ms compiling +      0ms waiting while compiling lib/core/marketplace/chat.ex
[profile] Finished deadlock resolution in 0ms
    warning: you are implementing a protocol for Core.Marketplace.Chat.PropertyMessage but said module is not available. Make sure the module name is correct. If Core.Marketplace.Chat.PropertyMessage is an optional dependency, please wrap the protocol implementation in a Code.ensure_loaded?(Core.Marketplace.Chat.PropertyMessage) check
    │
  1 │ defimpl Core.Support.Factory.Builder, for: Core.Marketplace.Chat.PropertyMessage do
    │ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    │
    └─ test/support/factory/marketplace/chat/property_message.ex:1: (file)

[profile]     70ms compiling +    327ms waiting for module Core.Marketplace.Chat.PropertyMessage while compiling test/support/factory/marketplace/chat/property_message.ex
[profile]                    |     22ms waiting for module Core.Support.Factory.Builder while compiling test/support/factory/marketplace/chat/property_message.ex
[profile] Finished deadlock resolution in 0ms
[profile]   2112ms compiling +    446ms waiting for module :embedded while compiling lib/core/marketplace/chat/attachment.ex
[profile]   1178ms compiling +   2363ms waiting for module Core.Marketplace.Chat.Attachment while compiling lib/core/marketplace/chat/property_message.ex
[profile] Finished cycle resolution in 0ms
[profile] Finished compilation cycle of 9 modules in 3543ms
[profile] Finished group pass check of 9 modules in 97ms
Generated core app

Ohhh, right. I think maybe I also addressed that somewhere in ash. Did you update ash to latest too?

Yep, 3.9.0

can you try main of spark? I’ve added a hack just for :embedded that I shouldn’t have to do but would at least solve your issue in the short term :laughing:

Yep, spark in main fixed it for me