From 524c3ecef7954fbd1c7820b160426a069fef819f Mon Sep 17 00:00:00 2001 From: Christopher Piro Date: Sat, 13 Oct 2007 05:15:33 +0000 Subject: [PATCH] [thrift] make thrift_logger.erl more robust against badmatch Summary: more robust logic theres Reviewed By: eletuchy Test Plan: ok Revert Plan: ok Other Notes: the precommit hooks should forbid out-of-towners from being cited as reviewers git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665301 13f79535-47bb-0310-9956-ffa450edef68 --- lib/erl/src/thrift_logger.erl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/erl/src/thrift_logger.erl b/lib/erl/src/thrift_logger.erl index 13649a5f2..dee014b87 100644 --- a/lib/erl/src/thrift_logger.erl +++ b/lib/erl/src/thrift_logger.erl @@ -140,6 +140,8 @@ handle_event2(Symbol, Pid, Type, Message, State) -> % Message must be a string end. %% +-define(GS_TERM_FORMAT, "** Generic server ~p terminating \n** Last message in was ~p~n** When Server state == ~p~n** Reason for termination == ~n** ~p~n"). + handle_event1({What, _Gleader, {Ref, Format, Data}}, State) when is_list(Format) -> Symbol = case What of error -> "!!"; @@ -148,11 +150,8 @@ handle_event1({What, _Gleader, {Ref, Format, Data}}, State) when is_list(Format) _Else -> "??" end, - case Format of - "** Generic server ~p terminating \n** Last message in was ~p~n** When Server state == ~p~n** Reason for termination == ~n** ~p~n" -> - %% v- Pid is a pattern match, not a bind - [Ref, LastMessage, Obj, Reason] = Data, - + case {Format, Data} of + {?GS_TERM_FORMAT, [Ref, LastMessage, Obj, Reason]} -> %% TODO: move as much logic as possible out of thrift_logger Ignore = begin @@ -177,7 +176,10 @@ handle_event1({What, _Gleader, {Ref, Format, Data}}, State) when is_list(Format) Message = sformat(Format1, [LastMessage, oop:inspect(Obj), oop:inspect(Reason)]), %% TODO(cpiro): hope Reason is an object? handle_event2(Symbol, Ref, "", Message, State) end; - _ -> + {?GS_TERM_FORMAT, _Dta} -> + Message = sformat("DATA DIDN'T MATCH: ~p~n", [Data]) ++ sformat(Format, Data), + handle_event2(Symbol, Ref, "", Message, State); + {_Fmt, _Dta} -> Message = sformat(Format, Data), handle_event2(Symbol, Ref, "", Message, State) end,