Skip to content

Commit

Permalink
erlang/otp deprecated erlang:get_stacktrace/0 function, use the funct…
Browse files Browse the repository at this point in the history
…ion as platform version detected
  • Loading branch information
getong authored and velimir committed Dec 3, 2018
1 parent ba8c2c5 commit 70011b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions include/exception.hrl
@@ -0,0 +1,7 @@
-ifdef(OTP_RELEASE). %% this implies 21 or higher
-define(EXCEPTION(Class, Reason, Stacktrace), Class:Reason:Stacktrace).
-define(GET_STACK(Stacktrace), Stacktrace).
-else.
-define(EXCEPTION(Class, Reason, _), Class:Reason).
-define(GET_STACK(_), erlang:get_stacktrace()).
-endif.
7 changes: 4 additions & 3 deletions src/erllambda.erl
Expand Up @@ -25,7 +25,8 @@
%% private - handler invocation entry point, used by http api
-export([invoke/3]).

-include("include/erllambda.hrl").
-include("erllambda.hrl").
-include("exception.hrl").
-include_lib("erlcloud/include/erlcloud_aws.hrl").

-ifdef(TEST).
Expand Down Expand Up @@ -315,8 +316,8 @@ invoke_exec( Handler, Event, Context ) ->
% both top level handler and we can can call success/fail
throw:{?MODULE, result, JsonMap} -> {ok, JsonMap};
throw:{?MODULE, failure, JsonMap} -> {handled, JsonMap};
Type:Reason ->
Trace = erlang:get_stacktrace(),
?EXCEPTION(Type, Reason, Stacktrace) ->
Trace = ?GET_STACK(Stacktrace),
Message = format( "terminated with exception {~p, ~p}", [Type, Reason] ),
message_send( format( "~s with trace ~p", [Message, Trace] ) ),
Response = #{errorType => 'HandlerFailure',
Expand Down
6 changes: 3 additions & 3 deletions src/erllambda_config_srv.erl
Expand Up @@ -17,6 +17,7 @@
-export([start_link/0]).

-include("erllambda.hrl").
-include("exception.hrl").
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
Expand Down Expand Up @@ -152,9 +153,8 @@ serialize_run( Key, Generate ) ->
try
Generate()
catch
Type:Reason ->
Trace = erlang:get_stacktrace(),
{error, {exception, Type, Reason, Trace}}
?EXCEPTION(Type, Reason, Stacktrace) ->
{error, {exception, Type, Reason, ?GET_STACK(Stacktrace)}}
end,
Message = {complete, self(), Key, Result},
gen_server:cast( Parent, Message )
Expand Down

0 comments on commit 70011b7

Please sign in to comment.