Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Bugfix for crash on error_logger:error_report(not_std_error, [{a,b}]) #2

Closed
wants to merge 2 commits into from

2 participants

Brujo Benavides Scott Lystig Fritchie
Brujo Benavides

riak_err_handler crashed if you run > error_logger:error_report(not_std_err, [{a,b}]). from the console because riak_err_handler:format_event/2 was expecting a tuple with 4 elements as the result of riak_err_handler:perhaps_a_sasl_report/3 and it was getting just {ignore, ignore, ignore}.

Fernando Ben... added some commits November 24, 2010
Scott Lystig Fritchie
Owner

Fernando, thanks for the report and patch. I've created ticket #893.

https://issues.basho.com/show_bug.cgi?id=893

-Scott

Scott Lystig Fritchie
Owner

Fernando, we're experimenting with GitHub's pull & review tools.
Your request was handled via #3
and is now closed, thanks!

-Scott

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Nov 24, 2010
Bugfix for crash on error_logger:error_report(not_std_error, [{a,b}]) 9c839c9
Dialyzed e6f6db9
This page is out of date. Refresh to see the latest.
15  rebar.config
... ...
@@ -0,0 +1,15 @@
  1
+
  2
+{erl_opts, [warn_unused_vars,
  3
+            warn_export_all,
  4
+            warn_shadow_vars,
  5
+            warn_unused_import,
  6
+            warn_unused_function,
  7
+            warn_bif_clash,
  8
+            warn_unused_record,
  9
+            warn_deprecated_function,
  10
+            warn_obsolete_guard,
  11
+            strict_validation,
  12
+            warn_export_vars,
  13
+            warn_exported_vars,
  14
+            warn_missing_spec,
  15
+            warn_untyped_record, debug_info]}.
3  src/riak_err_app.erl
@@ -90,11 +90,14 @@
90 90
          start/2,
91 91
          stop/1]).
92 92
 
  93
+-spec start() -> 'ok' | {'error', term()}.
93 94
 start() ->
94 95
     application:start(riak_err).
95 96
 
  97
+-spec start(normal | {takeover, node()} | {failover, node()}, term()) -> {ok, pid()}.
96 98
 start(_StartType, _StartArgs) ->
97 99
     riak_err_sup:start_link().
98 100
 
  101
+-spec stop([]) -> ok.
99 102
 stop(_State) ->
100 103
     ok.
32  src/riak_err_handler.erl
@@ -52,11 +52,11 @@
52 52
          code_change/3]).
53 53
 
54 54
 -record(state, {
55  
-          term_max_size,
56  
-          fmt_max_bytes,
57  
-          log_path,
58  
-          log_fh,
59  
-          errlog_type
  55
+          term_max_size :: pos_integer(),
  56
+          fmt_max_bytes :: pos_integer(),
  57
+          log_path      :: undefined | string(),
  58
+          log_fh        :: undefined | file:io_device(),
  59
+          errlog_type   :: error | progress | all
60 60
          }).
61 61
 
62 62
 %%%----------------------------------------------------------------------
@@ -65,28 +65,28 @@
65 65
 
66 66
 %% @doc Add a supervised handler to the OTP kernel's
67 67
 %%      <tt>error_logger</tt> event server.
68  
-
  68
+-spec add_sup_handler() -> term().
69 69
 add_sup_handler() ->
70 70
     gen_event:add_sup_handler(error_logger, ?MODULE, []).
71 71
 
72 72
 %% @doc Change the internal value of <tt>set_term_max_size</tt>.
73  
-
  73
+-spec set_term_max_size(pos_integer()) -> ok.
74 74
 set_term_max_size(Num) ->
75 75
     gen_event:call(error_logger, ?MODULE, {set_term_max_size, Num}, infinity).
76 76
 
77 77
 %% @doc Change the internal value of <tt>set_fmt_max_bytes</tt>.
78  
-
  78
+-spec set_fmt_max_bytes(pos_integer()) -> ok.
79 79
 set_fmt_max_bytes(Num) ->
80 80
     gen_event:call(error_logger, ?MODULE, {set_fmt_max_bytes, Num}, infinity).
81 81
 
82 82
 %% @doc Tell our error handler to reopen the <tt>sasl_error_logger</tt> file's
83 83
 %%      file handle (e.g., to assist log file rotation schemes).
84  
-
  84
+-spec reopen_log_file() -> ok.
85 85
 reopen_log_file() ->
86 86
     gen_event:call(error_logger, riak_err_handler, reopen_log_file, infinity).
87 87
 
88 88
 %% @doc Debugging: get internal state record.
89  
-
  89
+-spec get_state() -> #state{}.
90 90
 get_state() ->
91 91
     gen_event:call(error_logger, ?MODULE, {get_state}, infinity).
92 92
 
@@ -99,6 +99,7 @@ get_state() ->
99 99
 %% Returns: {ok, State}          |
100 100
 %%          Other
101 101
 %%----------------------------------------------------------------------
  102
+-spec init([]) -> {ok, #state{}}.
102 103
 init([]) ->
103 104
     TermMaxSize = get_int_env(term_max_size, 10*1024),
104 105
     FmtMaxBytes = get_int_env(fmt_max_bytes, 12*1024),
@@ -125,6 +126,7 @@ init([]) ->
125 126
 %%          {swap_handler, Args1, State1, Mod2, Args2} |
126 127
 %%          remove_handler                              
127 128
 %%----------------------------------------------------------------------
  129
+-spec handle_event({atom(), pid(), {pid(), string() | atom(), any()}}, #state{}) -> {ok, #state{}}.
128 130
 handle_event(Event, State) ->
129 131
     Formatted = format_event(Event, State),
130 132
     io:put_chars(Formatted),
@@ -136,6 +138,7 @@ handle_event(Event, State) ->
136 138
 %%          {swap_handler, Reply, Args1, State1, Mod2, Args2} |
137 139
 %%          {remove_handler, Reply}                            
138 140
 %%----------------------------------------------------------------------
  141
+-spec handle_call(term(), #state{}) -> {ok, ok, #state{}}.
139 142
 handle_call(reopen_log_file, State) ->
140 143
     case State#state.log_fh of
141 144
         undefined ->
@@ -161,6 +164,7 @@ handle_call(_Request, State) ->
161 164
 %%          {swap_handler, Args1, State1, Mod2, Args2} |
162 165
 %%          remove_handler                              
163 166
 %%----------------------------------------------------------------------
  167
+-spec handle_info(term(), #state{}) -> {ok, #state{}}.
164 168
 handle_info(_Info, State) ->
165 169
     {ok, State}.
166 170
 
@@ -169,9 +173,11 @@ handle_info(_Info, State) ->
169 173
 %% Purpose: Shutdown the server
170 174
 %% Returns: any
171 175
 %%----------------------------------------------------------------------
  176
+-spec terminate(term(), #state{}) -> ok.
172 177
 terminate(_Reason, _State) ->
173 178
     ok.
174 179
 
  180
+-spec code_change(term(), #state{}, term()) -> {ok, #state{}}.
175 181
 code_change(_OldVsn, State, _Extra) ->
176 182
     {ok, State}.
177 183
 
@@ -248,7 +254,7 @@ perhaps_a_sasl_report(error_report, {Pid, Type, Report}, S) ->
248 254
             {sasl_type_to_report_head(Type), Pid,
249 255
              sasl_limited_str(Type, Report, S), true};
250 256
         false ->
251  
-            {ignore, ignore, ignore}
  257
+            {ignore, ignore, ignore, false}
252 258
     end;
253 259
 perhaps_a_sasl_report(info_report, {Pid, Type, Report}, S) ->
254 260
     case riak_err_stdlib:is_my_info_report(Type) of
@@ -256,10 +262,10 @@ perhaps_a_sasl_report(info_report, {Pid, Type, Report}, S) ->
256 262
             {sasl_type_to_report_head(Type), Pid,
257 263
              sasl_limited_str(Type, Report, S), false};
258 264
         false ->
259  
-            {ignore, ignore, ignore}
  265
+            {ignore, ignore, ignore, false}
260 266
     end;
261 267
 perhaps_a_sasl_report(_, _, _) ->
262  
-    {ignore, ignore, ignore}.
  268
+    {ignore, ignore, ignore, false}.
263 269
 
264 270
 sasl_type_to_report_head(supervisor_report) ->
265 271
     "SUPERVISOR REPORT";
25  src/riak_err_monitor.erl
@@ -31,16 +31,18 @@
31 31
          code_change/3]).
32 32
 
33 33
 -record(state, {
34  
-          max_len = 20*1024,
35  
-          tref
  34
+          max_len = 20*1024 :: pos_integer(),
  35
+          tref              :: timer:tref()
36 36
          }).
37 37
 
38 38
 %%%----------------------------------------------------------------------
39 39
 %%% API
40 40
 %%%----------------------------------------------------------------------
  41
+-spec start_link() -> {ok, pid()} | ignore | {error, term()}.
41 42
 start_link() ->
42 43
     gen_server:start_link({local, ?NAME}, ?MODULE, [], []).
43 44
 
  45
+-spec stop() -> ok.
44 46
 stop() ->
45 47
     gen_event:call(?NAME, stop, infinity).
46 48
 
@@ -55,14 +57,18 @@ stop() ->
55 57
 %%          ignore               |
56 58
 %%          {stop, Reason}
57 59
 %%----------------------------------------------------------------------
  60
+-spec init([]) -> {ok, #state{}}.
58 61
 init([]) ->
59 62
     %% Add our custom handler.
60 63
     ok = riak_err_handler:add_sup_handler(),
61 64
 
62 65
     %% Disable the default error logger handlers and SASL handlers.
63  
-    [gen_event:delete_handler(error_logger, Handler, {stop_please, ?MODULE}) ||
64  
-        Handler <- [error_logger, error_logger_tty_h, sasl_report_tty_h,
65  
-                    sasl_report_file_h]],
  66
+    ok = lists:foreach(
  67
+           fun(Handler) ->
  68
+                   gen_event:delete_handler(error_logger, Handler, {stop_please, ?MODULE})
  69
+           end,
  70
+           [error_logger, error_logger_tty_h, sasl_report_tty_h, sasl_report_file_h]),
  71
+    
66 72
     {ok, TRef} = timer:send_interval(1000, reopen_log_file),
67 73
     {ok, #state{tref = TRef}}.
68 74
 
@@ -75,8 +81,11 @@ init([]) ->
75 81
 %%          {stop, Reason, Reply, State}   | (terminate/2 is called)
76 82
 %%          {stop, Reason, State}            (terminate/2 is called)
77 83
 %%----------------------------------------------------------------------
  84
+-spec handle_call(stop | term(), reference(), #state{}) -> {stop, normal, ok, #state{}} | {reply, not_implemented, #state{}}.
  85
+handle_call(stop, _From, State) ->
  86
+  {stop, normal, ok, State};
78 87
 handle_call(_Request, _From, State) ->
79  
-    {reply, not_implemented, State}.
  88
+  {reply, not_implemented, State}.
80 89
 
81 90
 %%----------------------------------------------------------------------
82 91
 %% Func: handle_cast/2
@@ -84,6 +93,7 @@ handle_call(_Request, _From, State) ->
84 93
 %%          {noreply, State, Timeout} |
85 94
 %%          {stop, Reason, State}            (terminate/2 is called)
86 95
 %%----------------------------------------------------------------------
  96
+-spec handle_cast(tuple(), #state{}) -> {noreply, #state{}}.
87 97
 handle_cast(Msg, State) ->
88 98
     {Str, _} = trunc_io:print(Msg, State#state.max_len),
89 99
     error_logger:error_msg("~w: ~s:handle_cast got ~s\n",
@@ -96,6 +106,7 @@ handle_cast(Msg, State) ->
96 106
 %%          {noreply, State, Timeout} |
97 107
 %%          {stop, Reason, State}            (terminate/2 is called)
98 108
 %%----------------------------------------------------------------------
  109
+-spec handle_info(reopen_log_file | {gen_event_EXIT, ?MODULE, term()} | tuple(), #state{}) -> {noreply, #state{}} | {stop, gen_event_EXIT, #state{}}.
99 110
 handle_info(reopen_log_file, State) ->
100 111
     ok = riak_err_handler:reopen_log_file(),
101 112
     {noreply, State};
@@ -122,9 +133,11 @@ handle_info(Info, State) ->
122 133
 %% Purpose: Shutdown the server
123 134
 %% Returns: any (ignored by gen_server)
124 135
 %%----------------------------------------------------------------------
  136
+-spec terminate(term(), #state{}) -> ok.
125 137
 terminate(_Reason, _State) ->
126 138
     ok.
127 139
 
  140
+-spec code_change(term(), #state{}, term()) -> {ok, #state{}}.
128 141
 code_change(_OldVsn, State, _Extra) ->
129 142
     {ok, State}.
130 143
 
19  src/riak_err_stdlib.erl
@@ -30,9 +30,19 @@
30 30
 -export([sup_get/2]).
31 31
 -export([proc_lib_format/2]).
32 32
 
  33
+%% From calendar
  34
+-type year1970() :: 1970..10000.  % should probably be 1970..
  35
+-type month()    :: 1..12.
  36
+-type day()      :: 1..31.
  37
+-type hour()     :: 0..23.
  38
+-type minute()   :: 0..59.
  39
+-type second()   :: 0..59.
  40
+-type t_time()         :: {hour(),minute(),second()}.
  41
+-type t_datetime1970() :: {{year1970(),month(),day()},t_time()}.
  42
+
33 43
 %% From OTP stdlib's error_logger_tty_h.erl ... These functions aren't
34 44
 %% exported.
35  
-
  45
+-spec write_time({utc, t_datetime1970()} | t_datetime1970(), string()) -> string().
36 46
 write_time({utc,{{Y,Mo,D},{H,Mi,S}}},Type) ->
37 47
     io_lib:format("~n=~s==== ~p-~s-~p::~s:~s:~s UTC ===~n",
38 48
                   [Type,D,month(Mo),Y,t(H),t(Mi),t(S)]);
@@ -40,6 +50,7 @@ write_time({{Y,Mo,D},{H,Mi,S}},Type) ->
40 50
     io_lib:format("~n=~s==== ~p-~s-~p::~s:~s:~s ===~n",
41 51
                   [Type,D,month(Mo),Y,t(H),t(Mi),t(S)]).
42 52
 
  53
+-spec maybe_utc(t_datetime1970()) -> {utc, t_datetime1970()} | t_datetime1970().
43 54
 maybe_utc(Time) ->
44 55
     UTC = case application:get_env(sasl, utc_log) of
45 56
               {ok, Val} ->
@@ -86,14 +97,16 @@ month(12) -> "Dec".
86 97
 
87 98
 %% From OTP sasl's sasl_report.erl ... These functions aren't
88 99
 %% exported.
89  
-
  100
+-spec is_my_error_report(atom()) -> boolean().
90 101
 is_my_error_report(supervisor_report)   -> true;
91 102
 is_my_error_report(crash_report)        -> true;
92 103
 is_my_error_report(_)                   -> false.
93 104
 
  105
+-spec is_my_info_report(atom()) -> boolean().
94 106
 is_my_info_report(progress)  -> true;
95 107
 is_my_info_report(_)         -> false.
96 108
 
  109
+-spec sup_get(term(), [proplists:property()]) -> term().
97 110
 sup_get(Tag, Report) ->
98 111
     case lists:keysearch(Tag, 1, Report) of
99 112
         {value, {_, Value}} ->
@@ -103,7 +116,7 @@ sup_get(Tag, Report) ->
103 116
     end.
104 117
 
105 118
 %% From OTP stdlib's proc_lib.erl ... These functions aren't exported.
106  
-
  119
+-spec proc_lib_format([term()], pos_integer()) -> string().
107 120
 proc_lib_format([OwnReport,LinkReport], FmtMaxBytes) ->
108 121
     OwnFormat = format_report(OwnReport, FmtMaxBytes),
109 122
     LinkFormat = format_report(LinkReport, FmtMaxBytes),
6  src/riak_err_sup.erl
@@ -26,9 +26,15 @@
26 26
 
27 27
 -define(SERVER, ?MODULE).
28 28
 
  29
+%% From supervisor
  30
+-type startlink_err() :: {'already_started', pid()} | 'shutdown' | term().
  31
+-type startlink_ret() :: {'ok', pid()} | 'ignore' | {'error', startlink_err()}.
  32
+
  33
+-spec start_link() -> startlink_ret().
29 34
 start_link() ->
30 35
     supervisor:start_link({local, ?SERVER}, ?MODULE, []).
31 36
 
  37
+-spec init([]) -> {ok, {{one_for_one, 1000, 3600}, [supervisor:child_spec()]}}.
32 38
 init([]) ->
33 39
     RestartStrategy = one_for_one,
34 40
     MaxRestarts = 1000,
10  src/trunc_io.erl
@@ -36,6 +36,7 @@
36 36
 
37 37
 %% @doc Returns an flattened list containing the ASCII representation of the given
38 38
 %% term.
  39
+-spec fprint(term(), pos_integer()) -> string().
39 40
 fprint(T, Max) -> 
40 41
     {L, _} = print(T, Max),
41 42
     lists:flatten(L).
@@ -49,6 +50,7 @@ fprint(T, Max) ->
49 50
 %% depth-limited instead of length limited, so you might run out
50 51
 %% memory printing it. Out of the frying pan and into the fire.
51 52
 %% 
  53
+-spec safe(term(), pos_integer()) -> {string(), pos_integer()} | {string()}.
52 54
 safe(What, Len) ->
53 55
     case catch print(What, Len) of
54 56
 	{L, Used} when is_list(L) -> {L, Used};
@@ -56,6 +58,7 @@ safe(What, Len) ->
56 58
     end.	     
57 59
 
58 60
 %% @doc Returns {List, Length}
  61
+-spec print(term(), pos_integer()) -> {iolist(), pos_integer()}.
59 62
 print(_, Max) when Max < 0 -> {"...", 3};
60 63
 print(Tuple, Max) when is_tuple(Tuple) -> 
61 64
     {TC, Len} = tuple_contents(Tuple, Max-2),
@@ -166,9 +169,11 @@ alist(L, Max) ->
166 169
 
167 170
 %%--------------------
168 171
 %% The start of a test suite. So far, it only checks for not crashing.
  172
+-spec test() -> ok.
169 173
 test() ->
170 174
     test(trunc_io, print).
171 175
 
  176
+-spec test(atom(), atom()) -> ok.
172 177
 test(Mod, Func) ->
173 178
     Simple_items = [atom, 1234, 1234.0, {tuple}, [], [list], "string", self(),
174 179
 		    <<1,2,3>>, make_ref(), fun() -> ok end],
@@ -196,12 +201,14 @@ test(Mod, Func) ->
196 201
     
197 202
     lists:foreach(G, Tuples),
198 203
     lists:foreach(G, Lists).
199  
-    
  204
+
  205
+-spec perf() -> ok.
200 206
 perf() ->
201 207
     {New, _} = timer:tc(trunc_io, perf, [trunc_io, print, 1000]),
202 208
     {Old, _} = timer:tc(trunc_io, perf, [io_lib, write, 1000]),
203 209
     io:fwrite("New code took ~p us, old code ~p\n", [New, Old]).
204 210
 
  211
+-spec perf(atom(), atom(), integer()) -> done.
205 212
 perf(M, F, Reps) when Reps > 0 ->
206 213
     test(M,F),
207 214
     perf(M,F,Reps-1);
@@ -209,6 +216,7 @@ perf(_,_,_) ->
209 216
     done.    
210 217
 
211 218
 %% Performance test. Needs a particularly large term I saved as a binary...
  219
+-spec perf1() -> {non_neg_integer(), non_neg_integer()}.
212 220
 perf1() ->
213 221
     {ok, Bin} = file:read_file("bin"),
214 222
     A = binary_to_term(Bin),
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.