This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch remove-erlang-less-than-23
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 582cd6747219eac231945d0f41f4002166cede83
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Fri Jun 17 17:42:27 2022 -0400

    Remove Erlang < 23 ifdefs and other macros
---
 src/chttpd/src/chttpd.erl                          |  50 +++--
 src/chttpd/src/chttpd_stats.erl                    |   7 +-
 src/couch/include/couch_db.hrl                     |  24 ---
 src/couch/src/couch_httpd.erl                      | 237 ++++++++++++---------
 src/couch/src/couch_proc_manager.erl               |  10 +-
 src/couch/src/couch_query_servers.erl              |   9 +-
 src/couch/src/couch_util.erl                       |  23 --
 src/couch_log/src/couch_log_monitor.erl            |  12 --
 .../src/couch_replicator_scheduler_job.erl         |  93 ++++----
 src/ddoc_cache/src/ddoc_cache_entry.erl            |   5 +-
 src/fabric/src/fabric_rpc.erl                      |  34 +--
 src/fabric/src/fabric_util.erl                     |  14 --
 src/fabric/src/fabric_view_all_docs.erl            |  10 +-
 src/jwtf/src/jwtf.erl                              |  23 --
 src/mango/src/mango_httpd.erl                      |  10 +-
 src/mango/src/mango_util.erl                       |   6 +-
 src/rexi/src/rexi_server.erl                       |  45 ++--
 src/smoosh/src/smoosh_server.erl                   |   2 +-
 18 files changed, 286 insertions(+), 328 deletions(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index 48280e80c..1d7163799 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -349,17 +349,19 @@ before_request(HttpReq) ->
     try
         chttpd_stats:init(),
         chttpd_plugin:before_request(HttpReq)
-    catch ?STACKTRACE(ErrorType, Error, Stack)
-        {error, catch_error(HttpReq, ErrorType, Error, Stack)}
+    catch
+        ErrorType:Error:Stack ->
+            {error, catch_error(HttpReq, ErrorType, Error, Stack)}
     end.
 
 after_request(HttpReq, HttpResp0) ->
     {ok, HttpResp1} =
         try
             chttpd_plugin:after_request(HttpReq, HttpResp0)
-        catch ?STACKTRACE(_ErrorType, Error, Stack)
-            send_error(HttpReq, {Error, nil, Stack}),
-            {ok, HttpResp0#httpd_resp{status = aborted}}
+        catch
+            _ErrorType:Error:Stack ->
+                send_error(HttpReq, {Error, nil, Stack}),
+                {ok, HttpResp0#httpd_resp{status = aborted}}
         end,
     HttpResp2 = update_stats(HttpReq, HttpResp1),
     chttpd_stats:report(HttpReq, HttpResp2),
@@ -370,7 +372,7 @@ process_request(#httpd{mochi_req = MochiReq} = HttpReq) ->
     HandlerKey =
         case HttpReq#httpd.path_parts of
             [] -> <<>>;
-            [Key|_] -> ?l2b(quote(Key))
+            [Key | _] -> ?l2b(quote(Key))
         end,
 
     RawUri = MochiReq:get(raw_path),
@@ -380,29 +382,35 @@ process_request(#httpd{mochi_req = MochiReq} = HttpReq) ->
         check_request_uri_length(RawUri),
         check_url_encoding(RawUri),
         case chttpd_cors:maybe_handle_preflight_request(HttpReq) of
-        not_preflight ->
-            case chttpd_auth:authenticate(HttpReq, fun authenticate_request/1) 
of
-            #httpd{} = Req ->
-                handle_req_after_auth(HandlerKey, Req);
+            not_preflight ->
+                case chttpd_auth:authenticate(HttpReq, fun 
authenticate_request/1) of
+                    #httpd{} = Req ->
+                        handle_req_after_auth(HandlerKey, Req);
+                    Response ->
+                        {HttpReq, Response}
+                end;
             Response ->
                 {HttpReq, Response}
-            end;
-        Response ->
-            {HttpReq, Response}
         end
-    catch ?STACKTRACE(ErrorType, Error, Stack)
-        {HttpReq, catch_error(HttpReq, ErrorType, Error, Stack)}
+    catch
+        ErrorType:Error:Stack ->
+            {HttpReq, catch_error(HttpReq, ErrorType, Error, Stack)}
     end.
 
 handle_req_after_auth(HandlerKey, HttpReq) ->
     try
-        HandlerFun = chttpd_handlers:url_handler(HandlerKey,
-            fun chttpd_db:handle_request/1),
-        AuthorizedReq = chttpd_auth:authorize(possibly_hack(HttpReq),
-            fun chttpd_auth_request:authorize_request/1),
+        HandlerFun = chttpd_handlers:url_handler(
+            HandlerKey,
+            fun chttpd_db:handle_request/1
+        ),
+        AuthorizedReq = chttpd_auth:authorize(
+            possibly_hack(HttpReq),
+            fun chttpd_auth_request:authorize_request/1
+        ),
         {AuthorizedReq, HandlerFun(AuthorizedReq)}
-    catch ?STACKTRACE(ErrorType, Error, Stack)
-        {HttpReq, catch_error(HttpReq, ErrorType, Error, Stack)}
+    catch
+        ErrorType:Error:Stack ->
+            {HttpReq, catch_error(HttpReq, ErrorType, Error, Stack)}
     end.
 
 catch_error(_HttpReq, throw, {http_head_abort, Resp}, _Stack) ->
diff --git a/src/chttpd/src/chttpd_stats.erl b/src/chttpd/src/chttpd_stats.erl
index f6eb01659..080def454 100644
--- a/src/chttpd/src/chttpd_stats.erl
+++ b/src/chttpd/src/chttpd_stats.erl
@@ -48,9 +48,10 @@ report(HttpReq, HttpResp) ->
             _ ->
                 ok
         end
-    catch ?STACKTRACE(T, R, S)
-        Fmt = "Failed to report chttpd request stats: ~p:~p ~p",
-        couch_log:error(Fmt, [T, R, S])
+    catch
+        T:R:S ->
+            Fmt = "Failed to report chttpd request stats: ~p:~p ~p",
+            couch_log:error(Fmt, [T, R, S])
     end.
 
 report(HttpReq, HttpResp, St) ->
diff --git a/src/couch/include/couch_db.hrl b/src/couch/include/couch_db.hrl
index 019c205ab..633beebd0 100644
--- a/src/couch/include/couch_db.hrl
+++ b/src/couch/include/couch_db.hrl
@@ -218,27 +218,3 @@
 -type user_ctx() :: #user_ctx{}.
 -type sec_props() :: [tuple()].
 -type sec_obj() :: {sec_props()}.
-
-%% Erlang/OTP 21 deprecates and 23 removes get_stacktrace(), so
-%% we have to monkey around until we can drop support < 21.
-%% h/t https://github.com/erlang/otp/pull/1783#issuecomment-386190970
-
-%% use like so:
-% try function1(Arg1)
-% catch
-%     ?STACKTRACE(exit, badarg, ErrorStackTrace)
-%         % do stuff with ErrorStackTrace
-%         % ...
-% end,
-
-% Get the stacktrace in a way that is backwards compatible
-% OTP_VERSION is only available in OTP 21 and later, so we don’t need
-% to do any other version magic here.
--ifdef(OTP_RELEASE).
--define(STACKTRACE(ErrorType, Error, Stack),
-        ErrorType:Error:Stack ->).
--else.
--define(STACKTRACE(ErrorType, Error, Stack),
-        ErrorType:Error ->
-            Stack = erlang:get_stacktrace(),).
--endif.
diff --git a/src/couch/src/couch_httpd.erl b/src/couch/src/couch_httpd.erl
index 629cbbdcc..b5ca8bd29 100644
--- a/src/couch/src/couch_httpd.erl
+++ b/src/couch/src/couch_httpd.erl
@@ -295,8 +295,13 @@ handle_request(
         DesignUrlHandlers
     ).
 
-handle_request_int(MochiReq, DefaultFun,
-            UrlHandlers, DbUrlHandlers, DesignUrlHandlers) ->
+handle_request_int(
+    MochiReq,
+    DefaultFun,
+    UrlHandlers,
+    DbUrlHandlers,
+    DesignUrlHandlers
+) ->
     Begin = os:timestamp(),
     % for the path, use the raw path with the query string and fragment
     % removed, but URL quoting left intact
@@ -304,22 +309,25 @@ handle_request_int(MochiReq, DefaultFun,
     {"/" ++ Path, _, _} = mochiweb_util:urlsplit_path(RawUri),
 
     % get requested path
-    RequestedPath = case MochiReq:get_header_value("x-couchdb-vhost-path") of
-        undefined ->
-            case MochiReq:get_header_value("x-couchdb-requested-path") of
-                undefined -> RawUri;
-                R -> R
-            end;
-        P -> P
-    end,
+    RequestedPath =
+        case MochiReq:get_header_value("x-couchdb-vhost-path") of
+            undefined ->
+                case MochiReq:get_header_value("x-couchdb-requested-path") of
+                    undefined -> RawUri;
+                    R -> R
+                end;
+            P ->
+                P
+        end,
 
     HandlerKey =
-    case mochiweb_util:partition(Path, "/") of
-    {"", "", ""} ->
-        <<"/">>; % Special case the root url handler
-    {FirstPart, _, _} ->
-        list_to_binary(FirstPart)
-    end,
+        case mochiweb_util:partition(Path, "/") of
+            {"", "", ""} ->
+                % Special case the root url handler
+                <<"/">>;
+            {FirstPart, _, _} ->
+                list_to_binary(FirstPart)
+        end,
     couch_log:debug("~p ~s ~p from ~p~nHeaders: ~p", [
         MochiReq:get(method),
         RawUri,
@@ -329,41 +337,54 @@ handle_request_int(MochiReq, DefaultFun,
     ]),
 
     Method1 =
-    case MochiReq:get(method) of
-        % already an atom
-        Meth when is_atom(Meth) -> Meth;
-
-        % Non standard HTTP verbs aren't atoms (COPY, MOVE etc) so convert when
-        % possible (if any module references the atom, then it's existing).
-        Meth -> couch_util:to_existing_atom(Meth)
-    end,
+        case MochiReq:get(method) of
+            % already an atom
+            Meth when is_atom(Meth) -> Meth;
+            % Non standard HTTP verbs aren't atoms (COPY, MOVE etc) so convert 
when
+            % possible (if any module references the atom, then it's existing).
+            Meth -> couch_util:to_existing_atom(Meth)
+        end,
     increment_method_stats(Method1),
 
     % allow broken HTTP clients to fake a full method vocabulary with an 
X-HTTP-METHOD-OVERRIDE header
     MethodOverride = 
MochiReq:get_primary_header_value("X-HTTP-Method-Override"),
-    Method2 = case lists:member(MethodOverride, ["GET", "HEAD", "POST",
-                                                 "PUT", "DELETE",
-                                                 "TRACE", "CONNECT",
-                                                 "COPY"]) of
-    true ->
-        couch_log:info("MethodOverride: ~s (real method was ~s)",
-                       [MethodOverride, Method1]),
-        case Method1 of
-        'POST' -> couch_util:to_existing_atom(MethodOverride);
-        _ ->
-            % Ignore X-HTTP-Method-Override when the original verb isn't POST.
-            % I'd like to send a 406 error to the client, but that'd require a 
nasty refactor.
-            % throw({not_acceptable, <<"X-HTTP-Method-Override may only be 
used with POST requests.">>})
-            Method1
-        end;
-    _ -> Method1
-    end,
+    Method2 =
+        case
+            lists:member(MethodOverride, [
+                "GET",
+                "HEAD",
+                "POST",
+                "PUT",
+                "DELETE",
+                "TRACE",
+                "CONNECT",
+                "COPY"
+            ])
+        of
+            true ->
+                couch_log:info(
+                    "MethodOverride: ~s (real method was ~s)",
+                    [MethodOverride, Method1]
+                ),
+                case Method1 of
+                    'POST' ->
+                        couch_util:to_existing_atom(MethodOverride);
+                    _ ->
+                        % Ignore X-HTTP-Method-Override when the original verb 
isn't POST.
+                        % I'd like to send a 406 error to the client, but 
that'd require a nasty refactor.
+                        % throw({not_acceptable, <<"X-HTTP-Method-Override may 
only be used with POST requests.">>})
+                        Method1
+                end;
+            _ ->
+                Method1
+        end,
 
     % alias HEAD to GET as mochiweb takes care of stripping the body
-    Method = case Method2 of
-        'HEAD' -> 'GET';
-        Other -> Other
-    end,
+    Method =
+        case Method2 of
+            'HEAD' -> 'GET';
+            Other -> Other
+        end,
 
     HttpReq = #httpd{
         mochi_req = MochiReq,
@@ -383,66 +404,72 @@ handle_request_int(MochiReq, DefaultFun,
     HandlerFun = couch_util:dict_find(HandlerKey, UrlHandlers, DefaultFun),
 
     {ok, Resp} =
-    try
-        validate_host(HttpReq),
-        check_request_uri_length(RawUri),
-        case chttpd_cors:maybe_handle_preflight_request(HttpReq) of
-        not_preflight ->
-            case authenticate_request(HttpReq) of
-            #httpd{} = Req ->
-                HandlerFun(Req);
-            Response ->
-                Response
-            end;
-        Response ->
-            Response
-        end
-    catch
-        throw:{http_head_abort, Resp0} ->
-            {ok, Resp0};
-        throw:{invalid_json, S} ->
-            couch_log:error("attempted upload of invalid JSON"
-                            " (set log_level to debug to log it)", []),
-            couch_log:debug("Invalid JSON: ~p",[S]),
-            send_error(HttpReq, {bad_request, invalid_json});
-        throw:unacceptable_encoding ->
-            couch_log:error("unsupported encoding method for the response", 
[]),
-            send_error(HttpReq, {not_acceptable, "unsupported encoding"});
-        throw:bad_accept_encoding_value ->
-            couch_log:error("received invalid Accept-Encoding header", []),
-            send_error(HttpReq, bad_request);
-        exit:{shutdown, Error} ->
-            exit({shutdown, Error});
-        exit:normal ->
-            exit(normal);
-        exit:snappy_nif_not_loaded ->
-            ErrorReason = "To access the database or view index, Apache 
CouchDB"
-                          " must be built with Erlang OTP R13B04 or higher.",
-            couch_log:error("~s", [ErrorReason]),
-            send_error(HttpReq, {bad_otp_release, ErrorReason});
-        exit:{body_too_large, _} ->
-            send_error(HttpReq, request_entity_too_large);
-        exit:{uri_too_long, _} ->
-            send_error(HttpReq, request_uri_too_long);
-        ?STACKTRACE(throw, Error, Stack)
-            couch_log:debug("Minor error in HTTP request: ~p",[Error]),
-            couch_log:debug("Stacktrace: ~p",[Stack]),
-            send_error(HttpReq, Error);
-        ?STACKTRACE(error, badarg, Stack)
-            couch_log:error("Badarg error in HTTP request",[]),
-            couch_log:info("Stacktrace: ~p",[Stack]),
-            send_error(HttpReq, badarg);
-        ?STACKTRACE(error, function_clause, Stack)
-            couch_log:error("function_clause error in HTTP request",[]),
-            couch_log:info("Stacktrace: ~p",[Stack]),
-            send_error(HttpReq, function_clause);
-        ?STACKTRACE(ErrorType, Error, Stack)
-            couch_log:error("Uncaught error in HTTP request: ~p",
-                            [{ErrorType, Error}]),
-            couch_log:info("Stacktrace: ~p",[Stack]),
-            send_error(HttpReq, Error)
-    end,
-    RequestTime = round(timer:now_diff(os:timestamp(), Begin)/1000),
+        try
+            validate_host(HttpReq),
+            check_request_uri_length(RawUri),
+            case chttpd_cors:maybe_handle_preflight_request(HttpReq) of
+                not_preflight ->
+                    case authenticate_request(HttpReq) of
+                        #httpd{} = Req ->
+                            HandlerFun(Req);
+                        Response ->
+                            Response
+                    end;
+                Response ->
+                    Response
+            end
+        catch
+            throw:{http_head_abort, Resp0} ->
+                {ok, Resp0};
+            throw:{invalid_json, S} ->
+                couch_log:error(
+                    "attempted upload of invalid JSON"
+                    " (set log_level to debug to log it)",
+                    []
+                ),
+                couch_log:debug("Invalid JSON: ~p", [S]),
+                send_error(HttpReq, {bad_request, invalid_json});
+            throw:unacceptable_encoding ->
+                couch_log:error("unsupported encoding method for the 
response", []),
+                send_error(HttpReq, {not_acceptable, "unsupported encoding"});
+            throw:bad_accept_encoding_value ->
+                couch_log:error("received invalid Accept-Encoding header", []),
+                send_error(HttpReq, bad_request);
+            exit:{shutdown, Error} ->
+                exit({shutdown, Error});
+            exit:normal ->
+                exit(normal);
+            exit:snappy_nif_not_loaded ->
+                ErrorReason =
+                    "To access the database or view index, Apache CouchDB"
+                    " must be built with Erlang OTP R13B04 or higher.",
+                couch_log:error("~s", [ErrorReason]),
+                send_error(HttpReq, {bad_otp_release, ErrorReason});
+            exit:{body_too_large, _} ->
+                send_error(HttpReq, request_entity_too_large);
+            exit:{uri_too_long, _} ->
+                send_error(HttpReq, request_uri_too_long);
+            throw:Error:Stack ->
+                couch_log:debug("Minor error in HTTP request: ~p", [Error]),
+                couch_log:debug("Stacktrace: ~p", [Stack]),
+                send_error(HttpReq, Error);
+            error:badarg:Stack ->
+                couch_log:error("Badarg error in HTTP request", []),
+                couch_log:info("Stacktrace: ~p", [Stack]),
+                send_error(HttpReq, badarg);
+            error:function_clause:Stack ->
+                couch_log:error("function_clause error in HTTP request", []),
+                couch_log:info("Stacktrace: ~p", [Stack]),
+                send_error(HttpReq, function_clause);
+            ErrorType:Error:Stack ->
+                couch_log:error(
+                    "Uncaught error in HTTP request: ~p",
+                    [{ErrorType, Error}]
+                ),
+                couch_log:info("Stacktrace: ~p", [Stack]),
+                send_error(HttpReq, Error)
+        end,
+    RequestTime = round(timer:now_diff(os:timestamp(), Begin) / 1000),
     couch_stats:update_histogram([couchdb, request_time], RequestTime),
     couch_stats:increment_counter([couchdb, httpd, requests]),
     {ok, Resp}.
diff --git a/src/couch/src/couch_proc_manager.erl 
b/src/couch/src/couch_proc_manager.erl
index 6d86c16a7..46765b339 100644
--- a/src/couch/src/couch_proc_manager.erl
+++ b/src/couch/src/couch_proc_manager.erl
@@ -285,10 +285,12 @@ find_proc(#client{lang = Lang, ddoc = DDoc, ddoc_key = 
DDocKey} = Client) ->
     end.
 
 find_proc(Lang, Fun) ->
-    try iter_procs(Lang, Fun)
-    catch ?STACKTRACE(error, Reason, StackTrace)
-        couch_log:error("~p ~p ~p", [?MODULE, Reason, StackTrace]),
-        {error, Reason}
+    try
+        iter_procs(Lang, Fun)
+    catch
+        error:Reason:StackTrace ->
+            couch_log:error("~p ~p ~p", [?MODULE, Reason, StackTrace]),
+            {error, Reason}
     end.
 
 iter_procs(Lang, Fun) when is_binary(Lang) ->
diff --git a/src/couch/src/couch_query_servers.erl 
b/src/couch/src/couch_query_servers.erl
index 5dd7c4a4b..cb619405e 100644
--- a/src/couch/src/couch_query_servers.erl
+++ b/src/couch/src/couch_query_servers.erl
@@ -563,7 +563,7 @@ ddoc_prompt(DDoc, FunPath, Args) ->
         proc_prompt(Proc, [<<"ddoc">>, DDocId, FunPath, Args])
     end).
 
-with_ddoc_proc(#doc{id=DDocId,revs={Start, [DiskRev|_]}}=DDoc, Fun) ->
+with_ddoc_proc(#doc{id = DDocId, revs = {Start, [DiskRev | _]}} = DDoc, Fun) ->
     Rev = couch_doc:rev_to_str({Start, DiskRev}),
     DDocKey = {DDocId, Rev},
     Proc = get_ddoc_process(DDoc, DDocKey),
@@ -571,9 +571,10 @@ with_ddoc_proc(#doc{id=DDocId,revs={Start, 
[DiskRev|_]}}=DDoc, Fun) ->
         Resp ->
             ok = ret_os_process(Proc),
             Resp
-    catch ?STACKTRACE(Tag, Err, Stack)
-        catch proc_stop(Proc),
-        erlang:raise(Tag, Err, Stack)
+    catch
+        Tag:Err:Stack ->
+            catch proc_stop(Proc),
+            erlang:raise(Tag, Err, Stack)
     end.
 
 proc_prompt(Proc, Args) ->
diff --git a/src/couch/src/couch_util.erl b/src/couch/src/couch_util.erl
index 912c6dd8a..47e994300 100644
--- a/src/couch/src/couch_util.erl
+++ b/src/couch/src/couch_util.erl
@@ -782,32 +782,9 @@ check_config_blacklist(Section) ->
             ok
     end.
 
--ifdef(OTP_RELEASE).
-
--if(?OTP_RELEASE >= 22).
-
-% OTP >= 22
 hmac(Alg, Key, Message) ->
     crypto:mac(hmac, Alg, Key, Message).
 
--else.
-
-% OTP >= 21, < 22
-hmac(Alg, Key, Message) ->
-    crypto:hmac(Alg, Key, Message).
-
-% -if(?OTP_RELEASE >= 22)
--endif.
-
--else.
-
-% OTP < 21
-hmac(Alg, Key, Message) ->
-    crypto:hmac(Alg, Key, Message).
-
-% -ifdef(OTP_RELEASE)
--endif.
-
 version_to_binary(Ver) when is_tuple(Ver) ->
     version_to_binary(tuple_to_list(Ver));
 version_to_binary(Ver) when is_list(Ver) ->
diff --git a/src/couch_log/src/couch_log_monitor.erl 
b/src/couch_log/src/couch_log_monitor.erl
index b5ac0a844..e7e73100a 100644
--- a/src/couch_log/src/couch_log_monitor.erl
+++ b/src/couch_log/src/couch_log_monitor.erl
@@ -33,24 +33,12 @@
 start_link() ->
     gen_server:start_link(?MODULE, [], []).
 
-% OTP_RELEASE defined in OTP >= 21 only
--ifdef(OTP_RELEASE).
-
 init(_) ->
     % see https://erlang.org/doc/man/error_logger.html#add_report_handler-1
     ok = error_logger:add_report_handler(?HANDLER_MOD),
     ok = gen_event:add_sup_handler(error_logger, ?HANDLER_MOD, []),
     {ok, nil}.
 
--else.
-
-init(_) ->
-    error_logger:start(),
-    ok = gen_event:add_sup_handler(error_logger, ?HANDLER_MOD, []),
-    {ok, nil}.
-
--endif.
-
 terminate(_, _) ->
     ok.
 
diff --git a/src/couch_replicator/src/couch_replicator_scheduler_job.erl 
b/src/couch_replicator/src/couch_replicator_scheduler_job.erl
index 777636691..2ae8718ad 100644
--- a/src/couch_replicator/src/couch_replicator_scheduler_job.erl
+++ b/src/couch_replicator/src/couch_replicator_scheduler_job.erl
@@ -255,88 +255,80 @@ handle_cast(
 
 handle_info(shutdown, St) ->
     {stop, shutdown, St};
-
 handle_info({'EXIT', Pid, max_backoff}, State) ->
     couch_log:error("Max backoff reached child process ~p", [Pid]),
     {stop, {shutdown, max_backoff}, State};
-
 handle_info({'EXIT', Pid, {shutdown, max_backoff}}, State) ->
     couch_log:error("Max backoff reached child process ~p", [Pid]),
     {stop, {shutdown, max_backoff}, State};
-
-handle_info({'EXIT', Pid, normal}, #rep_state{changes_reader=Pid} = State) ->
+handle_info({'EXIT', Pid, normal}, #rep_state{changes_reader = Pid} = State) ->
     {noreply, State};
-
-handle_info({'EXIT', Pid, Reason0}, #rep_state{changes_reader=Pid} = State) ->
+handle_info({'EXIT', Pid, Reason0}, #rep_state{changes_reader = Pid} = State) 
->
     couch_stats:increment_counter([couch_replicator, changes_reader_deaths]),
-    Reason = case Reason0 of
-        {changes_req_failed, _, _} = HttpFail ->
-            HttpFail;
-        {http_request_failed, _, _, {error, {code, Code}}} ->
-            {changes_req_failed, Code};
-        {http_request_failed, _, _, {error, Err}} ->
-            {changes_req_failed, Err};
-        Other ->
-            {changes_reader_died, Other}
-    end,
+    Reason =
+        case Reason0 of
+            {changes_req_failed, _, _} = HttpFail ->
+                HttpFail;
+            {http_request_failed, _, _, {error, {code, Code}}} ->
+                {changes_req_failed, Code};
+            {http_request_failed, _, _, {error, Err}} ->
+                {changes_req_failed, Err};
+            Other ->
+                {changes_reader_died, Other}
+        end,
     couch_log:error("ChangesReader process died with reason: ~p", [Reason]),
     {stop, {shutdown, Reason}, cancel_timer(State)};
-
 handle_info({'EXIT', Pid, normal}, #rep_state{changes_manager = Pid} = State) 
->
     {noreply, State};
-
 handle_info({'EXIT', Pid, Reason}, #rep_state{changes_manager = Pid} = State) 
->
     couch_stats:increment_counter([couch_replicator, changes_manager_deaths]),
     couch_log:error("ChangesManager process died with reason: ~p", [Reason]),
     {stop, {shutdown, {changes_manager_died, Reason}}, cancel_timer(State)};
-
-handle_info({'EXIT', Pid, normal}, #rep_state{changes_queue=Pid} = State) ->
+handle_info({'EXIT', Pid, normal}, #rep_state{changes_queue = Pid} = State) ->
     {noreply, State};
-
-handle_info({'EXIT', Pid, Reason}, #rep_state{changes_queue=Pid} = State) ->
+handle_info({'EXIT', Pid, Reason}, #rep_state{changes_queue = Pid} = State) ->
     couch_stats:increment_counter([couch_replicator, changes_queue_deaths]),
     couch_log:error("ChangesQueue process died with reason: ~p", [Reason]),
     {stop, {shutdown, {changes_queue_died, Reason}}, cancel_timer(State)};
-
 handle_info({'EXIT', Pid, normal}, #rep_state{workers = Workers} = State) ->
     case Workers -- [Pid] of
-    Workers ->
-        couch_log:error("unknown pid bit the dust ~p ~n",[Pid]),
-        {noreply, State#rep_state{workers = Workers}};
+        Workers ->
+            couch_log:error("unknown pid bit the dust ~p ~n", [Pid]),
+            {noreply, State#rep_state{workers = Workers}};
         %% not clear why a stop was here before
         %%{stop, {unknown_process_died, Pid, normal}, State};
-    [] ->
-        catch unlink(State#rep_state.changes_manager),
-        catch exit(State#rep_state.changes_manager, kill),
-        do_last_checkpoint(State);
-    Workers2 ->
-        {noreply, State#rep_state{workers = Workers2}}
+        [] ->
+            catch unlink(State#rep_state.changes_manager),
+            catch exit(State#rep_state.changes_manager, kill),
+            do_last_checkpoint(State);
+        Workers2 ->
+            {noreply, State#rep_state{workers = Workers2}}
     end;
-
 handle_info({'EXIT', Pid, Reason}, #rep_state{workers = Workers} = State) ->
     State2 = cancel_timer(State),
     case lists:member(Pid, Workers) of
-    false ->
-        {stop, {unknown_process_died, Pid, Reason}, State2};
-    true ->
-        couch_stats:increment_counter([couch_replicator, worker_deaths]),
-        StopReason = case Reason of
-            {shutdown, _} = Err ->
-                Err;
-            Other ->
-                couch_log:error("Worker ~p died with reason: ~p", [Pid, 
Reason]),
-                {worker_died, Pid, Other}
-         end,
-        {stop, StopReason, State2}
+        false ->
+            {stop, {unknown_process_died, Pid, Reason}, State2};
+        true ->
+            couch_stats:increment_counter([couch_replicator, worker_deaths]),
+            StopReason =
+                case Reason of
+                    {shutdown, _} = Err ->
+                        Err;
+                    Other ->
+                        couch_log:error("Worker ~p died with reason: ~p", 
[Pid, Reason]),
+                        {worker_died, Pid, Other}
+                end,
+            {stop, StopReason, State2}
     end;
-
 handle_info(timeout, InitArgs) ->
-    try do_init(InitArgs) of {ok, State} ->
-        {noreply, State}
+    try do_init(InitArgs) of
+        {ok, State} ->
+            {noreply, State}
     catch
         exit:{http_request_failed, _, _, max_backoff} ->
             {stop, {shutdown, max_backoff}, {error, InitArgs}};
-        ?STACKTRACE(Class, Error, Stack)
+        Class:Error:Stack ->
             ShutdownReason = {error, replication_start_error(Error)},
             StackTop2 = lists:sublist(Stack, 2),
             % Shutdown state is a hack as it is not really the state of the
@@ -344,8 +336,7 @@ handle_info(timeout, InitArgs) ->
             % Shutdown state is used to pass extra info about why start failed.
             ShutdownState = {error, Class, StackTop2, InitArgs},
             {stop, {shutdown, ShutdownReason}, ShutdownState}
-        end;
-
+    end;
 handle_info({Ref, Tuple}, State) when is_reference(Ref), is_tuple(Tuple) ->
     % Ignore responses from timed-out or retried ibrowse calls. Aliases in
     % Erlang 24 should help with this problem, so we should revisit this clause
diff --git a/src/ddoc_cache/src/ddoc_cache_entry.erl 
b/src/ddoc_cache/src/ddoc_cache_entry.erl
index 5a1711dd8..ea8e4c228 100644
--- a/src/ddoc_cache/src/ddoc_cache_entry.erl
+++ b/src/ddoc_cache/src/ddoc_cache_entry.erl
@@ -275,8 +275,9 @@ do_open(Key) ->
     try recover(Key) of
         Resp ->
             erlang:exit({open_ok, Key, Resp})
-    catch ?STACKTRACE(T, R, S)
-        erlang:exit({open_error, Key, {T, R, S}})
+    catch
+        T:R:S ->
+            erlang:exit({open_error, Key, {T, R, S}})
     end.
 
 update_lru(#st{key = Key, ts = Ts} = St) ->
diff --git a/src/fabric/src/fabric_rpc.erl b/src/fabric/src/fabric_rpc.erl
index 8780737ef..5db84458a 100644
--- a/src/fabric/src/fabric_rpc.erl
+++ b/src/fabric/src/fabric_rpc.erl
@@ -349,21 +349,29 @@ get_uuid(DbName) ->
 %% internal
 %%
 
-with_db(DbName, Options, {M,F,A}) ->
+with_db(DbName, Options, {M, F, A}) ->
     set_io_priority(DbName, Options),
     case get_or_create_db(DbName, Options) of
-    {ok, Db} ->
-        rexi:reply(try
-            apply(M, F, [Db | A])
-        catch Exception ->
-            Exception;
-        ?STACKTRACE(error, Reason, Stack)
-            couch_log:error("rpc ~p:~p/~p ~p ~p", [M, F, length(A)+1, Reason,
-                clean_stack(Stack)]),
-            {error, Reason}
-        end);
-    Error ->
-        rexi:reply(Error)
+        {ok, Db} ->
+            rexi:reply(
+                try
+                    apply(M, F, [Db | A])
+                catch
+                    Exception ->
+                        Exception;
+                    error:Reason:Stack ->
+                        couch_log:error("rpc ~p:~p/~p ~p ~p", [
+                            M,
+                            F,
+                            length(A) + 1,
+                            Reason,
+                            clean_stack(Stack)
+                        ]),
+                        {error, Reason}
+                end
+            );
+        Error ->
+            rexi:reply(Error)
     end.
 
 read_repair_filter(DbName, Docs, NodeRevs, Options) ->
diff --git a/src/fabric/src/fabric_util.erl b/src/fabric/src/fabric_util.erl
index 30e82c29a..34e095403 100644
--- a/src/fabric/src/fabric_util.erl
+++ b/src/fabric/src/fabric_util.erl
@@ -413,9 +413,6 @@ isolate(Fun, Timeout) ->
         erlang:error(timeout)
     end.
 
-% OTP_RELEASE is defined in OTP 21+ only
--ifdef(OTP_RELEASE).
-
 do_isolate(Fun) ->
     try
         {'$isolres', Fun()}
@@ -424,17 +421,6 @@ do_isolate(Fun) ->
             {'$isolerr', Tag, Reason, Stack}
     end.
 
--else.
-
-do_isolate(Fun) ->
-    try
-        {'$isolres', Fun()}
-    catch ?STACKTRACE(Tag, Reason, Stack)
-        {'$isolerr', Tag, Reason, Stack}
-    end.
-
--endif.
-
 get_db_timeout_test() ->
     % Q=1, N=1
     ?assertEqual(20000, get_db_timeout(1, 2, 100, 60000)),
diff --git a/src/fabric/src/fabric_view_all_docs.erl 
b/src/fabric/src/fabric_view_all_docs.erl
index 0a637a738..7821dcf72 100644
--- a/src/fabric/src/fabric_view_all_docs.erl
+++ b/src/fabric/src/fabric_view_all_docs.erl
@@ -322,10 +322,12 @@ open_doc(DbName, Options, Id, IncludeDocs) ->
     try open_doc_int(DbName, Options, Id, IncludeDocs) of
         #view_row{} = Row ->
             exit(Row)
-    catch ?STACKTRACE(Type, Reason, Stack)
-        couch_log:error("_all_docs open error: ~s ~s :: ~w ~w", [
-                DbName, Id, {Type, Reason}, Stack]),
-        exit({Id, Reason})
+    catch
+        Type:Reason:Stack ->
+            couch_log:error("_all_docs open error: ~s ~s :: ~w ~w", [
+                DbName, Id, {Type, Reason}, Stack
+            ]),
+            exit({Id, Reason})
     end.
 
 open_doc_int(DbName, Options, Id, IncludeDocs) ->
diff --git a/src/jwtf/src/jwtf.erl b/src/jwtf/src/jwtf.erl
index b8b30c4f6..01f4be3cb 100644
--- a/src/jwtf/src/jwtf.erl
+++ b/src/jwtf/src/jwtf.erl
@@ -371,32 +371,9 @@ now_seconds() ->
 prop(Prop, Props) ->
     proplists:get_value(Prop, Props).
 
--ifdef(OTP_RELEASE).
-
--if(?OTP_RELEASE >= 22).
-
-% OTP >= 22
 hmac(Alg, Key, Message) ->
     crypto:mac(hmac, Alg, Key, Message).
 
--else.
-
-% OTP >= 21, < 22
-hmac(Alg, Key, Message) ->
-    crypto:hmac(Alg, Key, Message).
-
-% -if(?OTP_RELEASE >= 22)
--endif.
-
--else.
-
-% OTP < 21
-hmac(Alg, Key, Message) ->
-    crypto:hmac(Alg, Key, Message).
-
-% -ifdef(OTP_RELEASE)
--endif.
-
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").
 
diff --git a/src/mango/src/mango_httpd.erl b/src/mango/src/mango_httpd.erl
index 002c45b2f..3e58288da 100644
--- a/src/mango/src/mango_httpd.erl
+++ b/src/mango/src/mango_httpd.erl
@@ -35,12 +35,12 @@ handle_req(#httpd{} = Req, Db0) ->
         Db = set_user_ctx(Req, Db0),
         handle_req_int(Req, Db)
     catch
-        ?STACKTRACE(throw, {mango_error, Module, Reason}, Stack)
+        throw:{mango_error, Module, Reason}:Stack ->
             case mango_error:info(Module, Reason) of
-            {500, ErrorStr, ReasonStr} ->
-                chttpd:send_error(Req, {ErrorStr, ReasonStr, Stack});
-            {Code, ErrorStr, ReasonStr} ->
-                chttpd:send_error(Req, Code, ErrorStr, ReasonStr)
+                {500, ErrorStr, ReasonStr} ->
+                    chttpd:send_error(Req, {ErrorStr, ReasonStr, Stack});
+                {Code, ErrorStr, ReasonStr} ->
+                    chttpd:send_error(Req, Code, ErrorStr, ReasonStr)
             end
     end.
 
diff --git a/src/mango/src/mango_util.erl b/src/mango/src/mango_util.erl
index 609a9dbc0..c7ab1c8a6 100644
--- a/src/mango/src/mango_util.erl
+++ b/src/mango/src/mango_util.erl
@@ -131,13 +131,13 @@ do_defer(Mod, Fun, Args) ->
         Resp ->
             erlang:exit({mango_defer_ok, Resp})
     catch
-        ?STACKTRACE(throw, Error, Stack)
+        throw:Error:Stack ->
             couch_log:error("Defered error: ~w~n    ~p", [{throw, Error}, 
Stack]),
             erlang:exit({mango_defer_throw, Error});
-        ?STACKTRACE(error, Error, Stack)
+        error:Error:Stack ->
             couch_log:error("Defered error: ~w~n    ~p", [{error, Error}, 
Stack]),
             erlang:exit({mango_defer_error, Error});
-        ?STACKTRACE(exit, Error, Stack)
+        exit:Error:Stack ->
             couch_log:error("Defered error: ~w~n    ~p", [{exit, Error}, 
Stack]),
             erlang:exit({mango_defer_exit, Error})
     end.
diff --git a/src/rexi/src/rexi_server.erl b/src/rexi/src/rexi_server.erl
index 47c128d7b..738e93543 100644
--- a/src/rexi/src/rexi_server.erl
+++ b/src/rexi/src/rexi_server.erl
@@ -138,24 +138,37 @@ init_p(From, MFA) ->
     {atom(), atom(), list()},
     string() | undefined
 ) -> any().
-init_p(From, {M,F,A}, Nonce) ->
+init_p(From, {M, F, A}, Nonce) ->
     put(rexi_from, From),
-    put('$initial_call', {M,F,length(A)}),
+    put('$initial_call', {M, F, length(A)}),
     put(nonce, Nonce),
-    try apply(M, F, A) catch exit:normal -> ok; ?STACKTRACE(Class, Reason, 
Stack0)
-        Stack = clean_stack(Stack0),
-        {ClientPid, _ClientRef} = From,
-        couch_log:error(
-            "rexi_server: from: ~s(~p) mfa: ~s:~s/~p ~p:~p ~100p", [
-            node(ClientPid), ClientPid, M, F, length(A),
-            Class, Reason, Stack]),
-        exit(#error{
-            timestamp = os:timestamp(),
-            reason = {Class, Reason},
-            mfa = {M,F,A},
-            nonce = Nonce,
-            stack = Stack
-        })
+    try
+        apply(M, F, A)
+    catch
+        exit:normal ->
+            ok;
+        Class:Reason:Stack0 ->
+            Stack = clean_stack(Stack0),
+            {ClientPid, _ClientRef} = From,
+            couch_log:error(
+                "rexi_server: from: ~s(~p) mfa: ~s:~s/~p ~p:~p ~100p", [
+                    node(ClientPid),
+                    ClientPid,
+                    M,
+                    F,
+                    length(A),
+                    Class,
+                    Reason,
+                    Stack
+                ]
+            ),
+            exit(#error{
+                timestamp = os:timestamp(),
+                reason = {Class, Reason},
+                mfa = {M, F, A},
+                nonce = Nonce,
+                stack = Stack
+            })
     end.
 
 %% internal
diff --git a/src/smoosh/src/smoosh_server.erl b/src/smoosh/src/smoosh_server.erl
index 50d80ce37..4ac7fd989 100644
--- a/src/smoosh/src/smoosh_server.erl
+++ b/src/smoosh/src/smoosh_server.erl
@@ -276,7 +276,7 @@ enqueue_request(State, Object) ->
             smoosh_channel:enqueue(Pid, Object, Priority)
         end
     catch
-        ?STACKTRACE(Class, Exception, Stack)
+        Class:Exception:Stack ->
         couch_log:warning("~s: ~p ~p for ~s : ~p",
             [?MODULE, Class, Exception,
                 smoosh_utils:stringify(Object), Stack])

Reply via email to