Merge pull request #38 from tnt-dev/fix-stacktrace

Stacktrace workaround for compatibility with OTP 21
This commit is contained in:
Jesse Gumm 2018-12-29 19:53:48 -06:00 committed by GitHub
commit b849ebde02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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.