Skip to content

Instantly share code, notes, and snippets.

@fjl
Forked from Gustav-Simonsson/stacktrace_filter.erl
Last active December 22, 2015 00:19
Show Gist options
  • Save fjl/6388452 to your computer and use it in GitHub Desktop.
Save fjl/6388452 to your computer and use it in GitHub Desktop.
-module(stacktrace_filter).
-compile(export_all).
t() ->
try
sensitive_data_function()
catch
Error:Reason ->
{Error, Reason, erlang:get_stacktrace()}
end.
t2() ->
try
sensitive_data_function()
catch
Error:Reason ->
ST = erlang:get_stacktrace(),
FilteredST = filter_stacktrace(ST),
{Error, Reason, FilteredST}
end.
filter_stacktrace(ST) ->
Filter =
fun({Module, Function, Args, Location}) when is_list(Args) ->
%% Replace args by arity, they might contain sensitive data
{Module, Function, length(Args), Location};
({Module, Function, Arity, Location}) ->
{Module, Function, Arity, Location}
end,
lists:map(Filter, ST).
sensitive_data_function() ->
lists:concat([secret], {"top_secret stuff!"}).
@andreionut
Copy link

This is good for R15, for R14 there is no location variable

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