Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Use compatible stack trace handling
Moved and cleaned up the stack trace handling to a shared header file. Cleaned-up file is developed by me and taken from basho/riak_core [1], based on this original code in Meck. [1]: https://github.com/basho/riak_core/blob/b726b0b4c5bbef1a20b95d551d3e32f6dc8741b5/src/stacktrace.hrl
- Loading branch information
Showing
3 changed files
with
43 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,34 @@ | ||
%% Copied from basho/riak_core. | ||
%% | ||
%% Fix to make Erlang programs compile on both OTP20 and OTP21. | ||
%% | ||
%% Get the stack trace in a way that is backwards compatible. Luckily | ||
%% OTP_RELEASE was introduced in the same version as the new preferred way of | ||
%% getting the stack trace. A _catch_/2 macro is provided for consistency in | ||
%% cases where the stack trace is not needed. | ||
%% | ||
%% Example use: | ||
%% try f(...) | ||
%% catch | ||
%% ?_exception_(_, Reason, StackToken) -> | ||
%% case Reason of | ||
%% {fail, Error} -> ok; | ||
%% _ -> {'EXIT', Reason, ?_get_stacktrace_(StackToken)} | ||
%% end | ||
%% end, | ||
|
||
-ifdef(OTP_RELEASE). %% This implies 21 or higher | ||
-define(_exception_(Class, Reason, StackToken), Class:Reason:StackToken). | ||
-define(_get_stacktrace_(StackToken), StackToken). | ||
-define(_current_stacktrace_(), | ||
try | ||
exit('$get_stacktrace') | ||
catch | ||
exit:'$get_stacktrace':__GetCurrentStackTrace -> | ||
__GetCurrentStackTrace | ||
end). | ||
-else. | ||
-define(_exception_(Class, Reason, _), Class:Reason). | ||
-define(_get_stacktrace_(_), erlang:get_stacktrace()). | ||
-define(_current_stacktrace_(), erlang:get_stacktrace()). | ||
-endif. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters