Packages

BEAM stack trace in Gleam: a stack trace of stack frames with module name, function name, arity, file name and line number.

Current section

Files

Jump to
stacky src stacky_ffi.erl
Raw

src/stacky_ffi.erl

-module(stacky_ffi).
-export([stacky_erlang_stack_trace/0]).
stacky_erlang_stack_trace() ->
FullStackTrace =
try
throw(test)
catch
_Class:_Reason:Stacktrace ->
Stacktrace
end,
[_FfiCallFrame, _StackyCallFrame | RestStacktrace] = FullStackTrace,
StackTrace = lists:map(fun(StackFrame) ->
case StackFrame of
{ModuleName, FunctionName, Arity, [{file, Filename}, {line, LineNumber}]} ->
{atom_to_binary(ModuleName),
atom_to_binary(FunctionName),
Arity,
iolist_to_binary(Filename),
LineNumber};
{ModuleName, FunctionName, Arity, []} ->
{atom_to_binary(ModuleName),
atom_to_binary(FunctionName),
Arity,
<<"unknown">>,
-1};
Other ->
erlang:display(Other),
% TODO: pass this through to the gleam layer and somehow dump the information on the user
throw("unexpected stack frame data - please report this as a potential bug")
end
end,
RestStacktrace),
ReversedStackTrace = lists:reverse(StackTrace),
IndexedStackTrace = lists:enumerate(ReversedStackTrace),
lists:reverse(IndexedStackTrace).