Skip to content

Fix funs error: no match of right hand side value: nil#73

Merged
sasa1977 merged 2 commits intosasa1977:masterfrom
gaggle:patch-1
Jul 15, 2025
Merged

Fix funs error: no match of right hand side value: nil#73
sasa1977 merged 2 commits intosasa1977:masterfrom
gaggle:patch-1

Conversation

@gaggle
Copy link
Contributor

@gaggle gaggle commented Jul 9, 2025

I encountered error:

== Compilation error in file lib/my_app/mailer.ex ==
** (MatchError) no match of right hand side value: nil
    (boundary 0.10.4) lib/boundary/mix/tasks/visualize/funs.ex:48: Mix.Tasks.Boundary.Visualize.Funs.trace/2
    (elixir 1.18.4) src/elixir_env.erl:30: :elixir_env."-trace/2-lc$^0/1-0-"/3
    (elixir 1.18.4) src/elixir_env.erl:30: :elixir_env.trace/2

This was due to a module like this:

defmodule MyApp.Mailer do
  use Boundary, deps: [], exports: []
  use Swoosh.Mailer, otp_app: :my_app
end

The fallback in this commit allows funs mix command to run successfully.

I encountered error running `funs` command in a module like this:

```elixir
defmodule MyApp.Mailer do
  use Boundary, deps: [], exports: []
  use Swoosh.Mailer, otp_app: :my_app
end
```

The fallback in this commit allows `funs` mix command to run successfully.
@gaggle gaggle changed the title Update funs.ex Fix funs error: no match of right hand side value: nil Jul 9, 2025
Comment on lines 44 to 51
{caller_fun, _arity} =
case env.function do
nil -> {:__module__, 0} # fallback name for non-function scope
tuple -> tuple
end

if inspect(env.module) == :persistent_term.get({__MODULE__, :module}) and caller_fun != callee_fun,
do: :ets.insert(__MODULE__, {caller_fun, callee_fun})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if instead of {:__module__, 0} we should simply ignore this case, so basically:

with {caller_fun, _arity} <- env.function,
     true <- inspect(env.module) == :persistent_term.get({__MODULE__, :module}),
     true <- caller_fun != callee_fun,
     do: :ets.insert(...)

:ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... yes, better than faking the function name.

Avoid inserting trace when `env.function` is nil
Comment on lines 43 to 49
def trace({local, _meta, callee_fun, _arity}, env) when local in ~w/local_function local_macro/a do
{caller_fun, _arity} = env.function

if inspect(env.module) == :persistent_term.get({__MODULE__, :module}) and caller_fun != callee_fun,
do: :ets.insert(__MODULE__, {caller_fun, callee_fun})
with {caller_fun, _arity} <- env.function,
true <- inspect(env.module) == :persistent_term.get({__MODULE__, :module}),
true <- caller_fun != callee_fun,
do: :ets.insert(__MODULE__, {caller_fun, callee_fun})

:ok
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sasa1977 now ignoring the case, per your suggested implementation 👍

@sasa1977 sasa1977 merged commit 84e580f into sasa1977:master Jul 15, 2025
@sasa1977
Copy link
Owner

Thank you!

@gaggle gaggle deleted the patch-1 branch August 26, 2025 18:04
@gaggle
Copy link
Contributor Author

gaggle commented Aug 27, 2025

Hi @sasa1977, I can confirm the fix works.

May I inquire if this fix is scheduled for a release?

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

Successfully merging this pull request may close these issues.

2 participants