nietaki / rexbug

A thin Elixir wrapper for the redbug Erlang tracing debugger.
https://hexdocs.pm/rexbug/
MIT License
252 stars 15 forks source link

(FunctionClauseError) no function clause matching in Inspect.Algebra.container_each/6 #47

Closed dzfranklin closed 3 years ago

dzfranklin commented 4 years ago

Some targets cause errors, while others succeed. For example, Map fails but Map.new/_ works.

iex(5)> Rexbug.start("Map")                                             
{306, 46}
iex(6)> [error] Process #PID<0.865.0> raised an exception
** (FunctionClauseError) no function clause matching in Inspect.Algebra.container_each/6
    (elixir 1.11.0) lib/inspect/algebra.ex:397: Inspect.Algebra.container_each([binding: [], env: #Macro.Env<aliases: [], context: nil, context_modules: [], file: "iex", function: nil, functions: [{IEx.Helpers, [break!: 3, break!: 4, breaks: 0, ...]}, {Kernel, [!=: 2, !==: 2, ...]}], lexical_tracker: nil, line: 1, macro_aliases: [], macros: [{IEx.Helpers, ...}, {...}], module: nil, requires: [...], ...>, history: %IEx.History{queue: {[{4, {306, 1}}, {3, {306, 13}}, {2, nil}], [{1, {306, 13}}]}, size: 4, start: 1}, ref: #Reference<0.1974976076.3918790661.101797>, server: #PID<0.84.0>, stacktrace: nil], -1, %Inspect.Opts{base: :decimal, binaries: :infer, char_lists: :infer, charlists: :infer, custom_options: [], inspect_fun: &Inspect.inspect/2, limit: -1, pretty: false, printable_limit: 4096, safe: true, structs: true, syntax_colors: [], width: 80}, &Inspect.List.keyword/2, [], false)
    (elixir 1.11.0) lib/inspect/algebra.ex:385: Inspect.Algebra.container_doc/6
    (elixir 1.11.0) lib/kernel.ex:2132: Kernel.inspect/2
    (elixir 1.11.0) lib/enum.ex:1399: Enum."-map/2-lists^map/1-0-"/2
    (rexbug 1.0.4) lib/rexbug/printing.ex:50: Rexbug.Printing.MFA.represent/2
    (rexbug 1.0.4) lib/rexbug/printing.ex:97: Rexbug.Printing.Call.represent/2
    (rexbug 1.0.4) lib/rexbug/printing.ex:177: Rexbug.Printing.print_with_opts/2
    (redbug 1.2.2) /home/daniel/backpackingmap/server/deps/redbug/src/redbug.erl:313: anonymous fn/3 in :redbug.wrap_print_fun/1
    (stdlib 3.13.2) lists.erl:1267: :lists.foldl/3
    (redbug 1.2.2) /home/daniel/backpackingmap/server/deps/redbug/src/redbug.erl:529: :redbug.print_loop/2
redbug done, function_clause - [{'Elixir.Inspect.Algebra',container_each,
                                 [[{binding,[]},
                                   {env,
                                    #{'__struct__' => 'Elixir.Macro.Env',
                                      aliases => [],context => nil,
                                      context_modules => [],
                                      contextual_vars => [],
...

(full output: https://gist.github.com/danielzfranklin/ddc9aab8e7c0211821afa4d12c903832)

but

iex(15)> Rexbug.start("Map.new/_")
{306, 3}
iex(16)> Map.new()
%{}

# 21:24:08 #PID<0.842.0> IEx.Evaluator.init/4
# Map.new()

Versions: redbug 1.2.2 rexbug 1.0.4

vanvoljg commented 3 years ago

As far as I can see, it's because there's an invalid default limit applied in lib/rexbug/printing/util.ex. The limit is currently set to -1, but Elixir.Kernel.inspect/2 accepts only non-negative integers or :infinity as valid for the :limit option.

This is an issue only on Elixir versions >= 1.11.0 Relevant PR which made the changes that cause this error: https://github.com/elixir-lang/elixir/pull/10205

I think the limit should be set to :infinity, because we want Rexbug to print everything it can, but I may be incorrect about the original intent.

ahsf commented 3 years ago

@vanvoljg This seems to fix the issue, would you care to create a pull request?

jcelliott commented 3 years ago

Thanks for looking into this @vanvoljg. I just ran into this issue as well. Any chance we could get that PR merged?

nietaki commented 3 years ago

Hey @ahsf, @jcelliott @vanvoljg @danielzfranklin, I just released Rexbug v1.0.5, please have a look if it's better now.

This was an important issue and it has been raised a long time ago - sorry for not noticing it until someone pinged me. I have updated my Github notification settings to make such a situation less likely in the future. Regardless, don't hesitate to ping me if I'm not responding in a similar situation in the future.