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

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

Open
KronicDeth opened this issue Aug 24, 2020 · 0 comments
Open

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

KronicDeth opened this issue Aug 24, 2020 · 0 comments
Assignees
Labels
bug Something isn't working runtime
Milestone

Comments

@KronicDeth
Copy link
Collaborator

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}
@KronicDeth KronicDeth added bug Something isn't working runtime labels Aug 24, 2020
@KronicDeth KronicDeth added this to the ElixirConf 2020 milestone Aug 24, 2020
@KronicDeth KronicDeth modified the milestones: ElixirConf 2020, In 2020 Sep 3, 2020
@bcardarella bcardarella modified the milestones: In 2020, In 2021 Dec 9, 2020
@bitwalker bitwalker modified the milestones: In 2021, 2023 Mar 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working runtime
Projects
None yet
Development

No branches or pull requests

3 participants