Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

badarity must always include the stacktrace in the error reason #548

Description

@KronicDeth

When Lumen raises badarity and it is passed through a monitor, it has Info as {badarity, {Fun, Args}}, but it is supposed to be {{badarity, {Fun, Args}}, Stacktrace}. I believe this is the case because when badarity happens it counts as exit reason, which is always {reason, stacktrace}.

Lumen

init.erl

-module(init).
-export([start/0]).
-import(erlang, [display/1]).
-import(lumen, [log_exit/1]).

start() ->
  log_exit(false),
  {ParentPid, ParentMonitorReference} = spawn_monitor(fun () ->
    Options = [link, monitor],
    spawn_opt(fun (_) ->
      ok
    end, Options),
    wait_to_shutdown()
  end),
  receive
    {'DOWN', ParentMonitorReference, process, _, Info} ->
      case Info of
        {Reason = badarity, _FunArgs} ->
          display({parent, Reason});
        _ ->
          display({parent, Info})
      end
  after
    10 ->
      display({parent, alive, is_process_alive(ParentPid)})
  end.

wait_to_shutdown() ->
  receive
    shutdown -> ok
  end.

BEAM

start.erl

-module(start).
-export([start/0]).
-import(erlang, [display/1]).

start() ->
  {ParentPid, ParentMonitorReference} = spawn_monitor(fun () ->
    Options = [link, monitor],
    spawn_opt(fun (_) ->
      ok
    end, Options),
    wait_to_shutdown()
  end),
  receive
    {'DOWN', ParentMonitorReference, process, _, Info} ->
      case Info of
        {{Reason = badarity, _FunArgs}, _Stacktrace} ->
          display({parent, Reason});
        _ ->
          display({parent, Info})
      end
  after
    10 ->
      display({parent, alive, is_process_alive(ParentPid)})
  end,
  ok.

wait_to_shutdown() ->
  receive
    shutdown -> ok
  end.

Commands

  1. erl
  2. c(start).
  3. start:start().

Output

{parent,badarity}
ok
=ERROR REPORT==== 24-Aug-2020::11:52:33.289409 ===
Error in process <0.146.0> with exit value:
{{badarity,{#Fun<start.1.105435764>,[]}},[{erlang,apply,2,[]}]}

Difference with exit/1

It should be noted that exit(reason) DOES NOT include the stack trace and so counts whatever is passed to exit/1 as the "exit reason"

Commands

  1. erl
  2. catch exit(reason)

Output

{'EXIT', reason}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingruntime

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions