emit macro won't be able to check a lot of modules
Code in Elixir is compiled asynchronously. Therefore, loading all modules in compile times is not possible (because most modules are not even compiled yet), so some invocation of emit macro will just fail, because they will relate to the event of the not-yet compiled module
Hmm.. I'll try to reproduce this in our codebase! I admit at Vetspire we primarily rely on the @decorate and @decorate_all macros which don't need to bother doing any compile time checks because they define their own events.
Do you think some fix might be just adding a Code.ensure_compiled!/1 call to the emit/N macro? If I understand correctly this should cause module compilation to pause and await the ensure_compiled module is compiled and loaded no?
Do you think some fix might be just adding a Code.ensure_compiled!/1 call to the emit/N macro?
I don't think that it is possible to fix.
You can reproduce it in some setup like
defmodule First do
use Sibyl
@decorate trace()
def first_function do
emit(Second, :second_function)
end
end
And in other module
defmodule Second do
use Sybil
@decorate trace()
def second_function do
emit(First, :first_function)
end
end
Some module will be compiled first, and some module will be compiled second, therefore some function will be unable to check if event exists and defined
Overall, this issue can't be fixed. So the best approach would be to disable event? check or make it a runtime check or find some other way to check for existing event (like defining them in config.exs or such)