Stacktrace workaround for compatibility with OTP 21

This commit is contained in:
Pavel Abalikhin 2018-12-24 13:01:41 +03:00
parent fa59231e1e
commit 7314545b34

View file

@ -131,6 +131,13 @@
parse/1 parse/1
]). ]).
%% erlang:get_stacktrace/0 is deprecated in OTP 21
-ifndef(OTP_RELEASE).
-define(WITH_STACKTRACE(T, R, S), T:R -> S = erlang:get_stacktrace(), ).
-else.
-define(WITH_STACKTRACE(T, R, S), T:R:S ->).
-endif.
%% This the value in gregorian seconds for jan 1st 1970, 12am %% This the value in gregorian seconds for jan 1st 1970, 12am
%% It's used to convert to and from unixtime, since unixtime starts %% It's used to convert to and from unixtime, since unixtime starts
%% 1970-01-01 12:00am %% 1970-01-01 12:00am
@ -1076,8 +1083,7 @@ try_parsers(RawDate,[{ParserKey,Parser}|Parsers]) ->
Other -> Other ->
throw({invalid_parser_return_value,[{parser_key,ParserKey},{return,Other}]}) throw({invalid_parser_return_value,[{parser_key,ParserKey},{return,Other}]})
catch catch
Error:Reason -> ?WITH_STACKTRACE(Error, Reason, Stacktrace)
Stacktrace = erlang:get_stacktrace(),
throw({error_in_parser,[{error,{Error,Reason}},{parser_key,ParserKey}, {stacktrace, Stacktrace}]}) throw({error_in_parser,[{error,{Error,Reason}},{parser_key,ParserKey}, {stacktrace, Stacktrace}]})
end. end.