From 73ec1592e739fab4827515fb677fc5216378de7b Mon Sep 17 00:00:00 2001 From: Rick Chen Date: Wed, 23 Oct 2019 17:35:28 +0800 Subject: [PATCH 1/2] support otp 21 compat code from erlang-jose --- include/cluster_info_compat.hrl | 13 +++++++++++++ src/cluster_info.erl | 10 ++++++---- src/cluster_info_basic.erl | 10 ++++++---- 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 include/cluster_info_compat.hrl diff --git a/include/cluster_info_compat.hrl b/include/cluster_info_compat.hrl new file mode 100644 index 0000000..fafede5 --- /dev/null +++ b/include/cluster_info_compat.hrl @@ -0,0 +1,13 @@ +-ifndef(CLUSTER_INFO_COMPAT_HRL). + +-ifdef(OTP_RELEASE). %% this implies OTP 2-1 or higher +-define(COMPAT_CATCH(Class, Reason, Stacktrace), Class:Reason:Stacktrace). +-define(COMPAT_GET_STACKTRACE(Stacktrace), Stacktrace). +-else. +-define(COMPAT_CATCH(Class, Reason, _), Class:Reason). +-define(COMPAT_GET_STACKTRACE(_), erlang:get_stacktrace()). +-endif. + +-define(CLUSTER_INFO_COMPAT_HRL, 1). + +-endif. diff --git a/src/cluster_info.erl b/src/cluster_info.erl index c70e3a2..be99287 100644 --- a/src/cluster_info.erl +++ b/src/cluster_info.erl @@ -24,6 +24,8 @@ -define(DICT_KEY, '^_^--cluster_info'). +-include("cluster_info_compat.hrl"). + %% application callbacks %% Note: It is *not* necessary to start this application as a real/true OTP %% application before you can use it. The application behavior here @@ -118,9 +120,9 @@ dump_node(Node, Path, Opts) when is_atom(Node), is_list(Path) -> {ok, MRef} = gmt_util_make_monitor(Remote), Res = try ok = collect_remote_info(Remote, FH) - catch X:Y -> + catch ?COMPAT_CATCH(X, Y, ST) -> io:format("Error: ~P ~P at ~p\n", - [X, 20, Y, 20, erlang:get_stacktrace()]), + [X, 20, Y, 20, ?COMPAT_GET_STACKTRACE(ST)]), error after catch file:close(FH), @@ -262,9 +264,9 @@ dump_local_info(CPid, Opts) -> [Name, node()]), format_noescape(CPid, "
\n", []),
                           Fun(CPid)
-                      catch X:Y ->
+                      catch ?COMPAT_CATCH(X, Y, ST) ->
                               format(CPid, "Error in ~p: ~p ~p at ~p\n",
-                                     [Name, X, Y, erlang:get_stacktrace()])
+                                     [Name, X, Y, ?COMPAT_GET_STACKTRACE(ST)])
                       after
                           format_noescape(CPid, "
\n", []), format_noescape(CPid, "\n",[]) diff --git a/src/cluster_info_basic.erl b/src/cluster_info_basic.erl index 26fa94a..65c2a76 100644 --- a/src/cluster_info_basic.erl +++ b/src/cluster_info_basic.erl @@ -17,6 +17,8 @@ -module(cluster_info_basic). +-include("cluster_info_compat.hrl"). + %% Registration API -export([register/0]). @@ -76,9 +78,9 @@ application_info(C) -> cluster_info:format(C, " ~p\n\n", [application:get_all_key(App)]), cluster_info:format(C, " Application:get_all_env(~p):\n", [App]), cluster_info:format(C, " ~p\n\n", [application:get_all_env(App)]) - catch X:Y -> + catch ?COMPAT_CATCH(X, Y, ST) -> cluster_info:format(C, "Error for ~p: ~p ~p at ~p\n", - [App, X, Y, erlang:get_stacktrace()]) + [App, X, Y, ?COMPAT_GET_STACKTRACE(ST)]) end || App <- lists:sort([A || {A, _, _} <- application:which_applications()])]. capture_ets_i(C) -> @@ -166,9 +168,9 @@ loaded_modules(C) -> [try cluster_info:format(C, " Module ~p:\n", [Mod]), cluster_info:format(C, " ~p\n\n", [Mod:module_info()]) - catch X:Y -> + catch ?COMPAT_CATCH(X, Y, ST) -> cluster_info:format(C, "Error for ~p: ~p ~p at ~p\n", - [Mod, X, Y, erlang:get_stacktrace()]) + [Mod, X, Y, ?COMPAT_GET_STACKTRACE(ST)]) end || Mod <- lists:sort([M || {M, _} <- code:all_loaded()])]. memory_hogs(C, Num) -> From 0cf46211437baae1a06d9e068dbccd0f0c3be674 Mon Sep 17 00:00:00 2001 From: Rick Chen Date: Wed, 23 Oct 2019 17:38:12 +0800 Subject: [PATCH 2/2] minor fix --- include/cluster_info_compat.hrl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cluster_info_compat.hrl b/include/cluster_info_compat.hrl index fafede5..4b7c5e9 100644 --- a/include/cluster_info_compat.hrl +++ b/include/cluster_info_compat.hrl @@ -1,6 +1,6 @@ -ifndef(CLUSTER_INFO_COMPAT_HRL). --ifdef(OTP_RELEASE). %% this implies OTP 2-1 or higher +-ifdef(OTP_RELEASE). %% this implies OTP 21 or higher -define(COMPAT_CATCH(Class, Reason, Stacktrace), Class:Reason:Stacktrace). -define(COMPAT_GET_STACKTRACE(Stacktrace), Stacktrace). -else.