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

willholley pushed a commit to branch upstream-2.20.0
in repository https://gitbox.apache.org/repos/asf/couchdb-mochiweb.git

commit ef4f886c1a7c80891de6d4bb0b7ca1b8f4587a13
Author: Bob Ippolito <[email protected]>
AuthorDate: Mon Mar 11 22:45:20 2019 +0000

    Remove compile(tuple_calls) from the template
---
 .../mochiwebapp_skel/src/mochiapp_web.erl          | 47 +++++++++++++++-------
 1 file changed, 33 insertions(+), 14 deletions(-)

diff --git a/support/templates/mochiwebapp_skel/src/mochiapp_web.erl 
b/support/templates/mochiwebapp_skel/src/mochiapp_web.erl
index 7ffb44d..ecd99c5 100644
--- a/support/templates/mochiwebapp_skel/src/mochiapp_web.erl
+++ b/support/templates/mochiwebapp_skel/src/mochiapp_web.erl
@@ -6,8 +6,6 @@
 -module({{appid}}_web).
 -author("{{author}}").
 
--compile(tuple_calls).
-
 -export([start/1, stop/0, loop/2]).
 
 %% External API
@@ -22,35 +20,56 @@ start(Options) ->
 stop() ->
     mochiweb_http:stop(?MODULE).
 
+
+%% OTP 21 is the first to define OTP_RELEASE and the first to support
+%% EEP-0047 direct stack trace capture.
+-ifdef(OTP_RELEASE).
+-if(?OTP_RELEASE >= 21).
+-define(HAS_DIRECT_STACKTRACE, true).
+-endif.
+-endif.
+
+-ifdef(HAS_DIRECT_STACKTRACE).
+-define(CAPTURE_EXC_PRE(Type, What, Trace), Type:What:Trace).
+-define(CAPTURE_EXC_GET(Trace), Trace).
+-else.
+-define(CAPTURE_EXC_PRE(Type, What, Trace), Type:What).
+-define(CAPTURE_EXC_GET(Trace), erlang:get_stacktrace()).
+-endif.
+
 loop(Req, DocRoot) ->
-    "/" ++ Path = Req:get(path),
+    "/" ++ Path = mochiweb_request:get(path, Req),
     try
-        case Req:get(method) of
+        case mochiweb_request:get(method, Req) of
             Method when Method =:= 'GET'; Method =:= 'HEAD' ->
                 case Path of
-                  "hello_world" ->
-                    Req:respond({200, [{"Content-Type", "text/plain"}],
-                    "Hello world!\n"});
+                    "hello_world" ->
+                        mochiweb_request:respond(
+                            {200, [{"Content-Type", "text/plain"}], "Hello 
world!\n"},
+                            Req
+                        );
                     _ ->
-                        Req:serve_file(Path, DocRoot)
+                        mochiweb_request:serve_file(Path, DocRoot, Req)
                 end;
             'POST' ->
                 case Path of
                     _ ->
-                        Req:not_found()
+                        mochiweb_request:not_found(Req)
                 end;
             _ ->
-                Req:respond({501, [], []})
+                mochiweb_request:respond({501, [], []}, Req)
         end
     catch
-        Type:What ->
+        ?CAPTURE_EXC_PRE(Type, What, Trace) ->
             Report = ["web request failed",
                       {path, Path},
                       {type, Type}, {what, What},
-                      {trace, erlang:get_stacktrace()}],
+                      {trace, ?CAPTURE_EXC_GET(Trace)}],
             error_logger:error_report(Report),
-            Req:respond({500, [{"Content-Type", "text/plain"}],
-                         "request failed, sorry\n"})
+            mochiweb_request:respond(
+                {500, [{"Content-Type", "text/plain"}], "request failed, 
sorry\n"},
+                Req
+            )
     end.
 
 %% Internal API

Reply via email to